This file is indexed.

/usr/sbin/grid-mapfile-delete-entry 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
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
#!/bin/sh

# 
# 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-delete-entry
#

if test -n "${GLOBUS_LOCATION}" ; then
    prefix="${GLOBUS_LOCATION}"
else
    prefix="/usr"
fi

exec_prefix="${prefix}"
sbindir="${exec_prefix}/sbin"
bindir="${exec_prefix}/bin"
libdir="${prefix}/lib"
includedir="${prefix}/include/globus"
datarootdir="${prefix}/share"
datadir="${datarootdir}"
libexecdir="${datadir}/globus"
sysconfdir="/etc"
sharedstatedir="/var/lib"
localstatedir="/var"
aclocaldir="${datadir}/globus/aclocal"

. ${libexecdir}/globus-script-initializer

globus_source ${libexecdir}/globus-sh-tools.sh

PROGRAM_NAME=`echo $0 |${GLOBUS_SH_SED-sed} 's|.*/||g'`

PROGRAM_VERSION=`echo '$Revision: 1.13 $'| ${GLOBUS_SH_SED-sed} -e 's|\\$||g' -e 's|Revision: \(.*\)|\1|'`

VERSION="9.0"

PACKAGE="globus_gss_assist"

DIRT_TIMESTAMP="1382981921"

DIRT_BRANCH_ID="83"

short_usage="$PROGRAM_NAME [-help] [-dn <DN>] [-ln <local name>] [-d] [-f file]"

long_usage() {

    ${GLOBUS_SH_CAT-cat} >&2 <<EOF

${short_usage}

    $PROGRAM_NAME deletes one or more matching entries from the Grid mapfile.

    Options:
    -help, -usage           Displays help
    -version                Displays version
    -dn <DN>                Distinguished Name (DN) to delete
    -ln <local name>        Local Login Name (LN) to delete
    -dryrun, -d             Shows what would be done but will not
    delete the entry
    -mapfile file, -f file  Path of gridmap file to be used

EOF
}

globus_source $libexecdir/globus-args-parser-header $@

##############################################
Cleanup()
{
    if [ -f $DELETED_ENTRIES ] ; then
        ${GLOBUS_SH_RM-rm} $DELETED_ENTRIES
    fi

    if [ -f $CONSISTENCY_CHECK ] ; then
	${GLOBUS_SH_RM-rm} $CONSISTENCY_CHECK
    fi

    if [ -f $GRID_MAP_FILE_COPY ] ; then
	${GLOBUS_SH_RM-rm} $GRID_MAP_FILE_COPY
    fi

    if [ -f $NEW_GRID_MAP_FILE ] ; then
	${GLOBUS_SH_RM-rm} $NEW_GRID_MAP_FILE
    fi

    ${GLOBUS_SH_CHMOD-chmod} 644 $GRID_MAP_FILE
    if [ $? -ne 0 ] ; then
        echo "ERROR: Could not change mode of $GRID_MAP_FILE back to 644" >&2
        exit 1
    fi

}

removeLNs ()
{
    parseLine
    aux_line=$existing_ln

    for name in $ln ; do
	modif_line=$aux_line
	aux_line=`echo $aux_line | ${GLOBUS_SH_SED-sed} -e "s/,$name,/,/" -e "s/,$name$//" -e "s/^$name,//" -e "s/^$name$//"`
	if test ! "$modif_line" = "$aux_line" ; then
	    removed_map="$removed_map $name"
	    removed_map_count=`expr $removed_map_count + 1`
	fi
    done

    if test -n "$aux_line" ; then
	aux_line="\"$existing_dn\" $aux_line"
    fi
}

parseLine()
{
    # Check for double quote delimitor
    delim=`echo $line | cut -c1`
    if [ "X$delim" = "X\"" ]; then
        # DN is double quote delimited
        # Check for terminating double quote
        term_check=`echo $line | cut -c2- | ${GLOBUS_SH_GREP-grep} \"`
        if [ -z "$term_check" ]; then
            echo "The following entry is missing a closing double quote"
            echo "$line"
            Cleanup
            exit 1
        fi
        existing_dn=`echo $line | cut -f2 -d\"`
        existing_ln=`echo $line | cut -f3 -d\"`
    else
        # No double quote delimitor on DN
        existing_dn=`echo $line | ${GLOBUS_SH_SED-sed} -e 's/\([^	 ]*\)[	 ]*.*/\1/'`
	existing_ln=`echo $line | ${GLOBUS_SH_SED-sed} -e 's/[^	 ]*[	 ]*\(.*\)/\1/'`
    fi

    existing_ln=`echo ${existing_ln} | ${GLOBUS_SH_SED-sed} -e 's/[	 ]*//g'`
}

# Main Logic

secconfdir="/etc/grid-security"
GRID_MAP_FILE=${GRIDMAP-${secconfdir}/grid-mapfile}
ECHO_DRYRUN=:
deleted_entries=0
removed_map_count=0

# Parse command line arguments

if [ $# -lt 2 ] ; then
    globus_args_short_usage
    exit 1
fi

while [ -n "$1" ]; do
    case "$1" in
        -dn) 
	    shift
            if [ $# -ge 1 ] ; then
		dn=$1
                shift
	    else
                globus_args_option_error "-dn" "needs a DN argument"
	    fi
            ;;
        -ln )
            shift
            if [ $# -ge 1 ] ; then
		ln=$1
		shift
		if [ $# -ge 1 ] ; then
		    while [ "$1" != "-dn" -a "$1" != "-d" \
                        -a "$1" != "-dryrun" -a "$1" != "-f" \
                        -a "$1" != "-mapfile" ] ; do
                      ln=$ln" "$1
                      shift
                      if [ $# -eq 0 ] ; then
                          break
                      fi
		    done
		fi
	    else
                globus_args_option_error "-ln" "needs a list of user login names"
		exit 1
	    fi
	    ;;
        -d | -dryrun )
	    ECHO_DRYRUN=echo
	    shift
	    ;;
        -f | -mapfile )
	    opt=$1
	    shift
            if test $# -lt 1 ; then
                globus_args_option_error "$opt" "${opt} requires a argument"
            fi
	    GRID_MAP_FILE=$1
	    shift
	    ;;
        
        * )
	    globus_args_unrecognized_option "$1"
	    ;;
    esac

done

secure_tmpdir="`${GLOBUS_SH_DIRNAME-dirname} \"${GRID_MAP_FILE}\"`"

if test ! \( -r "${secure_tmpdir}" -a -w "${secure_tmpdir}" \) ; then
    echo "ERROR: This script requires read/write permissions in ${secure_tmpdir}" >&2
    exit 1
fi 

GRID_MAP_FILE_COPY=${secure_tmpdir}/.mapfile.copy.$$
NEW_GRID_MAP_FILE=${secure_tmpdir}/.new_mapfile.$$
CONSISTENCY_CHECK=${secure_tmpdir}/.consistency_check.$$
DELETED_ENTRIES=${secure_tmpdir}/.deleted_entries.$$

trap Cleanup 1 2 3 6 9 13 15

# Verify mapfile existence

if [ ! -f $GRID_MAP_FILE ] ; then
    globus_args_option_error "$opt" "\"${GRID_MAP_FILE}\" does not exist"
    exit 1
fi

if [ ! -r $GRID_MAP_FILE ] ; then
    globus_args_option_error "$opt" "\"${GRID_MAP_FILE}\" is not readable."
    exit 1
fi

if [ ! -w $GRID_MAP_FILE ] ; then
    globus_args_option_error "$opt" "\"${GRID_MAP_FILE}\" is not writeable."
    exit 1
fi

echo "Modifying ${GRID_MAP_FILE} ..."

# Make a copy of production map file for comparison to original later

${GLOBUS_SH_CP-cp} $GRID_MAP_FILE $GRID_MAP_FILE_COPY
if [ $? -ne 0 ] ; then
    echo "ERROR: Could not make a copy of $GRID_MAP_FILE" >&2
    Cleanup
    exit 1
fi

# Change mode of existing map file to read only (logical UNIX lock)

${GLOBUS_SH_CHMOD-chmod} 400 $GRID_MAP_FILE
if [ $? -ne 0 ] ; then
    echo "ERROR: Could not change mode of $GRID_MAP_FILE" >&2
    Cleanup
    exit 1
fi

if [ -n "$dn" -a -z "$ln" ] ; then
    requested_dn=$dn
    $ECHO_DRYRUN "Searching for entries containing the Distinguished Name"
    $ECHO_DRYRUN "$requested_dn"
elif [ -n "$ln" -a -z "$dn" ] ; then
    requested_ln=$ln
    $ECHO_DRYRUN "Searching for entries containing any of the Local Name(s)"
    $ECHO_DRYRUN "$requested_ln"
elif [ -n "$ln" -a -n "$dn" ] ; then
    requested_entry="\"$dn\" $ln"
    $ECHO_DRYRUN "Searching for entries containing the Distinguished Name and any of the Local Name(s)"
    $ECHO_DRYRUN "$requested_entry"
fi

# Create new map file

${GLOBUS_SH_TOUCH-touch} $NEW_GRID_MAP_FILE

while read line || test ! -z "${line}" ; do
    # Match ONLY DNs
		
    if test -n "$requested_dn" -a -z "$requested_ln" ; then
	
	parseLine 
	
	if test ! "$requested_dn" = "$existing_dn" ; then
	    echo $line >> $NEW_GRID_MAP_FILE
	else
	    echo "Deleting entry: $line"
	    deleted_entries=`expr $deleted_entries + 1`
	fi
	
    # Match ANY LNs
	
    elif test -z "$requested_dn" -a -n "$requested_ln" ; then
	found_match=""
	for name in $ln ; do
	    found_match=`echo $line | ${GLOBUS_SH_GREP-grep} $name`
	    if [ -n "$found_match" ] ; then
		break
	    fi
	done
	
	if [ -z "$found_match" ] ; then
	    echo $line >> $NEW_GRID_MAP_FILE
	else
	    removeLNs
	    if test -n "$aux_line" ; then
		echo "Current entry: $aux_line"
		echo $aux_line >> $NEW_GRID_MAP_FILE
	    else
		echo "No local mappings remained, deleting entry: $line"
	    fi
	fi
	
    # Match DN and list
	
    elif [ -n "$requested_entry" ] ; then
	
	parseLine 
	
	if test ! "$dn" = "$existing_dn" ; then
	    echo $line >> $NEW_GRID_MAP_FILE
	else
	    removeLNs
	    if test -n "$aux_line" ; then
		if test -n "$removed_map" ; then
		    echo "Current entry: $aux_line"
		fi
		echo $aux_line >> $NEW_GRID_MAP_FILE
	    else
		echo "No local mappings remained, deleting entry: $line"
	    fi
	fi
    fi
    
    echo $deleted_entries >  $DELETED_ENTRIES
    
done < $GRID_MAP_FILE_COPY

# Exit if Dry Run option was requested"
if [ -f "$DELETED_ENTRIES" ]; then
    deleted_entries=`cat $DELETED_ENTRIES`
else
    deleted_entries=0
fi

if [ "$ECHO_DRYRUN" = "echo" ] ; then
    if [ "$deleted_entries" -ne  0 ] ; then
	if [ "$deleted_entries" -eq  1 ] ; then
	    echo "($deleted_entries) entry would have been deleted"
	else
	    echo "($deleted_entries) entries would have been deleted"
	fi
    fi
    echo "Since ( dryrun, -d ) option was used no actions were carried out"
    Cleanup
    exit 0
fi

# Replace existing map file with new mapfile

if [ "$deleted_entries" -ne  0 ] || [ "$removed_map_count" -ne  0 ] ; then
    # Verify that no changes to original map file
    # during the execution of this program

    ${GLOBUS_SH_DIFF-diff} $GRID_MAP_FILE_COPY $GRID_MAP_FILE > $CONSISTENCY_CHECK
    if  [ -s $CONSISTENCY_CHECK ] ; then
	echo "ERROR: $GRID_MAP_FILE has changed since this program started" >&2
	echo "No changes will be made." >&2
	Cleanup
	exit 1
    else
      	# make copy of old map file
	
	${GLOBUS_SH_CP-cp} $GRID_MAP_FILE_COPY $GRID_MAP_FILE.old
	if [ $? -ne 0 ] ; then
	    echo "ERROR: Could not create a copy of $GRID_MAP_FILE" >&2
	fi
	
	# Restore old permissions on map file
	
	${GLOBUS_SH_CHMOD-chmod} 644 $GRID_MAP_FILE
	
	${GLOBUS_SH_MV-mv} $NEW_GRID_MAP_FILE $GRID_MAP_FILE
	
	if [ $? -ne 0 ] ; then
	    echo "ERROR: Could not create a new $GRID_MAP_FILE" >&2
	    Cleanup
	    exit 1
	fi
	
	removed_count=0
	ignored_count=0
	for name in $ln ; do
	    is_present=`echo $removed_map | ${GLOBUS_SH_GREP-grep} "$name"`
	    if  test -n "$is_present" ; then
		removed_count=`expr $removed_count + 1`
		printable_removed="$printable_removed $name"
	    else
		printable_ignored="$printable_ignored $name"
		ignored_count=`expr $ignored_count + 1`
	    fi
	done
	
	if  test -n "$printable_removed" ; then
	    printable_removed="`echo $printable_removed | sed -e "s/ /, /g"`"
	    printable_removed=": ($printable_removed)"
	fi
	if  test -n "$printable_ignored" ; then
	    printable_ignored="`echo $printable_ignored | sed -e "s/ /, /g"`"
	    printable_ignored=": ($printable_ignored)"
	fi
	
	if [ "$removed_count" -ne 0 ] ; then
	    if [ "$removed_count" -eq 1 ] ; then
		echo "($removed_count) mapping removed$printable_removed, ($ignored_count) not present and ignored$printable_ignored"
	    else
		echo "($removed_count) mappings removed$printable_removed, ($ignored_count) not present and ignored$printable_ignored"
	    fi
	fi
	
	if [ "$deleted_entries" -eq  1 ] ; then
	    echo "($deleted_entries) entry deleted"
	else
	    echo "($deleted_entries) entries deleted"
	fi
    fi
else
    echo "ERROR: No such entry/mapping exists"
    Cleanup
    exit 1
fi

Cleanup
exit 0