This file is indexed.

/usr/lib/ipsec/_realsetup is in openswan 1:2.6.37-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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
#!/bin/sh
# IPsec startup and shutdown command
# Copyright (C) 1998, 1999, 2001  Henry Spencer.
# 
# This program 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.  See <http://www.fsf.org/copyleft/gpl.txt>.
# 
# This program 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.
#

test $IPSEC_INIT_SCRIPT_DEBUG && set -v -x

LC_ALL=C export LC_ALL

me='ipsec setup'		# for messages

# Misc. paths (some of this should perhaps be overrideable from ipsec.conf).
plutopid=/var/run/pluto/pluto.pid
plutoctl=/var/run/pluto/pluto.ctl
subsysdir=/var/lock/subsys
subsyslock=/var/lock/subsys/ipsec
lock=/var/run/pluto/ipsec_setup.pid
info=/var/run/pluto/ipsec.info
sysflags=/proc/sys/net/ipsec
modules=/proc/modules
ipsecversion=/proc/net/ipsec_version
kamepfkey=/proc/net/pfkey

#pluto searches the current directory, so this is required for making it selinux compliant
cd /

#/etc/resolv.conf related paths
OPENSWAN_RESOLV_CONF=/var/run/pluto/openswan-resolv-conf-backup
ORIG_RESOLV_CONF=/etc/resolv.conf

# customize some things
if [ -f ${IPSEC_EXECDIR}/vendor ]; then
    VENDOR=`cat ${IPSEC_EXECDIR}/vendor`
fi

if test `ip addr list|grep -c cipsec` -ne 0
then
	echo "Cisco IPSec client is already loaded, aborting! (cipsec# device found)"
	exit 1
fi

# defaults for "config setup" items

#######################################################################
### WARNING: some of these defaults are set using addconn --configsetup
###          This will go away!
#######################################################################
IPSECinterfaces=${IPSECinterfaces:-%defaultroute}
IPSECinterfaces=${IPSECinterfaces%%%none}
# IPSECsyslog	"daemon.error"
# IPSECklipsdebug	"none"
# IPSECplutodebug	"none"
# IPSECdumpdir	"" (no dump)
# IPSECmanualstart	""
# IPSECpluto	"yes"
IPSECplutowait=${IPSECplutowait:-no}
# IPSECprepluto	""
# IPSECpostpluto	""
# IPSECfragicmp	"yes"
# IPSEChidetos	"yes"
IPSECuniqueids=${IPSECuniqueids:-yes}
IPSECdisable_port_floating=${IPSECdisable_port_floating:-no}
IPSECcrlcheckinterval=${IPSECcrlcheckinterval:-0}
IPSECprotostack=${IPSECprotostack:-auto}
# IPSECoverridemtu	""

# set defaults
mast=false
klips=false
netkey=false

# which kernel are we using?
case $IPSECprotostack in
auto)
    # for now, you can not auto-select mast
    #if test -f /proc/sys/net/ipsec/debug_mast
    if false
    then
    	netkey=false; klips=false; mast=true;
    elif test -f $kamepfkey
	then
	    netkey=true; klips=false;
	else
	    netkey=false; klips=true;
    fi;;
    
klips)  netkey=false; klips=true;  mast=false;;
mast)   netkey=false; klips=false; mast=true;;
netkey) 
    if test \! -f $kamepfkey
    then
        modprobe -q af_key;
    fi
	netkey=true;  klips=false; mast=false;;
none)   netkey=false; klips=false; mast=false;;
nostack) netkey=false; klips=false; mast=false;;
esac

# Shall we trace?
execute="true"
display="false"
for i in $IPSEC_setupflags
do
	case "$i" in
	"--showonly")	execute="false" ; display=true ;;
	"--show")	display=true ;;
	esac
done

if $display
then
	echo "	" PATH="$PATH"
fi

perform() {
	if $display
	then
		echo "	" "$*"
	fi

	if $execute
	then
		eval "$*"
	fi
}

# function to set up manually-keyed connections
manualconns() {
	if test " $IPSECmanualstart" != " "
	then
		for tu in $IPSECmanualstart
		do
			perform ipsec manual --up $tu
		done
	fi

	# search for things to "ipsec manual --up": auto == "manual"
	eval `ipsec addconn --varprefix MANUALSTART --search auto manual`
	if test " $MANUALSTART_confreadstatus" != " "
	then
		echo "auto=manual search: $MANUALSTART_confreadstatus"
		echo "unable to determine what conns to manual --up; none done"
	elif test " $MANUALSTART_confreadnames" != " "
	then
		for tu in $MANUALSTART_confreadnames
		do
			perform ipsec manual --up $tu
		done
	fi
}

# for no-stdout logging:
LOGONLY="logger -p $IPSECsyslog -t ipsec_setup"

# What an ugly string.
# Must be a string, not a function, because it is nested
# within another sequence (for plutorun).
# Luckily there are NO substitutions in it.

KILLKLIPS=":"

if $klips
then
        #
        # don't use ifconfig here,  there may be thousands of
        # interfaces to parse through,  much quicker to go
        # direct to the source
        #
    KILLKLIPS='ifl=`grep -v NULL /proc/net/ipsec_tncfg 2> /dev/null | sed -n -e "/^ipsec/s/ .*//p" ` ;
        test "X$ifl" != "X" &&
        for i in  $ifl ;
        do
		ip link set $i down ;
		ip addr flush dev $i ;
		ipsec tncfg --detach --virtual $i ;
	done ;
	test -r /proc/net/ipsec_klipsdebug && ipsec klipsdebug --none ;
	test -d /proc/net/ipsec/eroute && ipsec eroute --clear ;
	test -d /proc/net/ipsec/spi && ipsec spi --clear'
fi

if $netkey
then
	KILLKLIPS='
		if ip xfrm state > /dev/null 2>&1 ;
		then
			ip xfrm state flush ;
			ip xfrm policy flush ;
		elif type setkey > /dev/null 2>&1 ;
		then
			setkey -F ;
			setkey -FP ;
		fi'
fi



# do it
case "$1" in
  start|--start|_autostart)
	# First, does it seem to be going already?
	perform test ! -f $lock "||" "{" \
		echo "\"Openswan ${VENDOR}IPsec apparently already active, start aborted\"" ";" \
		exit 0 ";" \
		"}"

	# announcement
	# (Warning, changes to this log message may affect barf.)
	version="`ipsec --version | awk 'NR == 1 { print $(3) }' | sed -e 's/^U\(.*\)\/K(.*/\1/'`"
	case "$1" in
	start|--start)	perform echo "\"Starting Openswan ${VENDOR}IPsec $version...\""	;;
	_autostart)	perform echo "\"Restarting Openswan ${VENDOR}IPsec $version...\""	;;
	esac

	# preliminaries
	perform rm -f $lock
	mkdir -p $rundir > /dev/null 2>/dev/null
	chmod 700 $rundir > /dev/null 2>/dev/null
	mkdir -p $subsysdir > /dev/null 2>/dev/null

	for f in /dev/random /dev/urandom
	do
		perform test -r $f "||" "{" \
			echo "\"...unable to start Openswan ${VENDOR}IPsec, no $f!\"" ";" \
			exit 1 ";" \
			"}"
        done

	# the meaning of $$ at a different runtime is questionable!
	perform echo '$$' ">" $lock
	perform test -s $lock "||" "{" \
		echo "\"...unable to create $lock, aborting start!\"" ";" \
		rm -f $lock ";" \
		exit 1 ";" \
		"}"

	perform ">" $info

	# overridemtu is ignored on 2.6, so warn the user.
	# no longer warn about %defaultroute, because it has some use on
	# netkey for orienting ourselves when using left=%defaultroute
	if $netkey
	then
        	if test $IPSECoverridemtu
        	then
                	echo "WARNING: overridemtu= is ignored when using the NETKEY stack"
        	fi


		perform ipsec _startnetkey \
				--info $info \
				--debug "\"$IPSECklipsdebug\"" \
				--omtu "\"$IPSECoverridemtu\"" \
				--fragicmp "\"$IPSECfragicmp\"" \
				--hidetos "\"$IPSEChidetos\"" \
				--log "\"$IPSECsyslog\"" \
				$IPSECinterfaces "||" \
			"{" rm -f $lock ";" exit 1 ";" "}"
	fi

	if $klips || $mast
	then
		# here we go
		perform ipsec _startklips \
				--info $info \
				--debug "\"$IPSECklipsdebug\"" \
				--omtu "\"$IPSECoverridemtu\"" \
				--fragicmp "\"$IPSECfragicmp\"" \
				--hidetos "\"$IPSEChidetos\"" \
				--log "\"$IPSECsyslog\"" \
				$IPSECinterfaces "||" \
			"{" rm -f $lock ";" exit 1 ";" "}"

# Paul: Shouldn't the below tests be outside the klips test?

		perform test -f $ipsecversion "||" \
			test -f $kamepfkey "||" "{" \
			echo "\"OOPS, should have aborted!  Broken shell!\"" ";" \
			exit 1 ";" \
			"}"
	fi

	# misc pre-Pluto setup

	perform test -d $subsysdir "&&" touch $subsyslock

	manualconns

	plutorestartoncrash=""
	case "$IPSECplutorestartoncrash" in
	    true|[yY]|yes|restart) plutorestartoncrash="--plutorestartoncrash true";;
	    false|[nN]|no|die) plutorestartoncrash="--plutorestartoncrash false" ;;
        esac

	# Pluto
	case "$1" in
	start|--start)	re=	;;
	_autostart)	re=--re	;;
	esac
	if test " $IPSECpluto" != " no"
	then
		perform ipsec _plutorun $re \
			--debug "\"$IPSECplutodebug\"" \
			--uniqueids "\"$IPSECuniqueids\"" \
			--force_busy "\"$IPSECforce_busy\"" \
			--nocrsend "\"$IPSECnocrsend\"" \
			--strictcrlpolicy "\"$IPSECstrictcrlpolicy\"" \
			--nat_traversal "\"$IPSECnat_traversal\"" \
			--keep_alive "\"$IPSECkeep_alive\"" \
			--protostack "\"$IPSECprotostack\"" \
			--force_keepalive "\"$IPSECforce_keepalive\"" \
			--disable_port_floating "\"$IPSECdisable_port_floating\"" \
			--virtual_private "\"$IPSECvirtual_private\"" \
			--listen "\"$IPSEClisten\"" \
			--crlcheckinterval "\"$IPSECcrlcheckinterval\"" \
                        --ocspuri "\"$IPSECocspuri\"" \
			--nhelpers "\"$IPSECnhelpers\"" \
			--dump "\"$IPSECdumpdir\"" \
			--opts "\"$IPSECplutoopts\"" \
			--stderrlog "\"$IPSECplutostderrlog\"" \
			--wait "\"$IPSECplutowait\"" \
			--pre "\"$IPSECprepluto\"" \
			--post "\"$IPSECpostpluto\"" \
			--log "\"$IPSECsyslog\"" $plutorestartoncrash \
			--pid "\"$plutopid\"" "||" "{" \
		    $KILLKLIPS ";" \
		    rm -f $lock ";" \
		    exit 1 ";" \
		    "}"
	fi

	# done!
	perform echo "\"...Openswan ${VENDOR}IPsec started\"" "|" $LOGONLY
	;;

  stop|--stop|_autostop)		# _autostop is same as stop
	# Shut things down.
	perform echo "\"Stopping Openswan ${VENDOR}IPsec...\""
	perform \
		if test -r $lock ";" \
		then \
			status=0 ";" \
			. $info ";" \
		else \
			echo "\"stop ordered, but IPsec appears to be already stopped!\"" ";" \
			echo "\"doing cleanup anyway...\"" ";" \
			status=0 ";" \
		fi

	if [ -f /var/run/pluto.pid -a ! -f /var/run/pluto/pluto.pid ]
	then
	    mkdir -p /var/run/pluto
	    mv /var/run/pluto.pid /var/run/pluto/pluto.pid
	fi

	perform test -f $plutopid "&&" "{" \
		if test -d '/proc/`' cat $plutopid '`' ">" /dev/null ";" \
		then \
			ipsec whack --shutdown "|" grep -v "^002" ";" \
			sleep 1 ";" \
			if test -s $plutopid ";" \
			then \
				echo "\"Attempt to shut Pluto down failed!  Trying kill:\"" ";" \
				kill '`' cat $plutopid '`' ";" \
				sleep 5 ";" \
			fi ";" \
		else \
			echo "\"Removing orphaned $plutopid:\"" ";" \
		fi ";" \
		rm -f $plutopid ";" \
		"}"

	perform $KILLKLIPS
	rm -f /var/run/pluto.pid

	#cleaning up backup resolv.conf
	perform test -e $OPENSWAN_RESOLV_CONF "&&" "{" \
		if grep 'Openswan' $ORIG_RESOLV_CONF > /dev/null 2>&1 ";" \
		then \
			cp $OPENSWAN_RESOLV_CONF $ORIG_RESOLV_CONF ";" \
		else \
			echo "\"Current resolv.conf is not generated by Openswan, so doing nothing\"" ";" \
		fi ";" \
		rm -f  $OPENSWAN_RESOLV_CONF ";" \
		"}"

	# When we exit we clean up (remove) the modules we are using, even the kame'ish ones
	if test -e ${kamepfkey}; then
		for mod in ipcomp ipcomp6 xfrm6_tunnel xfrm6_mode_tunnel xfrm6_mode_beet xfrm6_mode_ro \
			xfrm6_mode_transport xfrm4_mode_transport xfrm4_mode_tunnel  xfrm_user \
			xfrm4_tunnel xfrm4_mode_beet esp4 esp6 ah4 ah6 af_key \
			xfrm_ipcomp tunnel6
		    do
			lsmod 2>&1 | grep "^$mod" > /dev/null && rmmod  $mod
		    done
	fi 

	if test -e ${ipsecversion}; then
		lsmod 2>&1 | grep "ipsec" > /dev/null && rmmod  ipsec
	fi

	perform test -d $subsysdir "&&" rm -f $subsyslock

	perform rm -f $info $lock $plutopid
	perform echo "...Openswan ${VENDOR}IPsec stopped" "|" $LOGONLY
	perform exit \$status
	;;

  status|--status)
	if test " $IPSEC_setupflags" != " "
	then
		echo "$me $1 does not support $IPSEC_setupflags"
		exit 4
	fi

	if test -f $info
	then
		hasinfo=yes
	fi

	if test -f $lock
	then
		haslock=yes
	fi

	if test -f $subsyslock
	then
		hassublock=yes
	fi

	if test -s $plutopid
	then
		if test -d /proc/`cat $plutopid 2> /dev/null` >/dev/null
		then
			plutokind=normal
		elif ps -C pluto >/dev/null
		then
			plutokind=illicit
		else
			plutokind=dead
		fi
	elif ps -C pluto >/dev/null
	then
		plutokind=orphaned
	else
		plutokind=no
	fi

	if test -r /proc/net/ipsec_eroute
	then
		eroutes=`wc -l < /proc/net/ipsec_eroute 2> /dev/null | sed s/\ //g`
	else
		eroutes=`ipsec auto --status 2> /dev/null | grep -c -i "ipsec sa established"`
	fi

	if test -r $ipsecversion
	then
		klips=yes
	elif test -r $modules
	then
		klips=maybe
	else
		klips=none
	fi
		
	if test -r $kamepfkey
	then
		lk26sec=yes
	fi

	if test "$hassublock" -a "$haslock" -a "$plutokind" = "normal" -a \( "$klips" = "yes" -o "$lk26sec" = "yes" \)  -a "$hasinfo"
	then
		echo "IPsec running"  " - pluto pid: `cat $plutopid 2>/dev/null`"
		echo "pluto pid `cat $plutopid`"
		case "$eroutes" in
			0)      echo "No tunnels up"    ;;
			*)      echo "$eroutes tunnels up"      ;;
		esac
		if test "$eroutes" -gt 0
		then
			echo "some eroutes exist"
		fi
		exit 0
	else
		echo "IPsec stopped"
		if test ! "$hassublock" -a ! "$hasinfo" -a "$plutokind" = "no" -a "$eroutes" -eq 0
		then
			exit 3
		fi
		echo "but..."
		if test "$plutokind" != "no"
		then
			echo "An ${plutokind} Pluto is active?"
			exit 1
		fi

		if test "$hassublock"
		then
			echo "has subsystem lock ($subsyslock)!"
			exit 2
		fi
		if test "$hasinfo"
		then
			echo "has $info file!"
		fi
		if test "$eroutes" -gt 0
		then
			echo "some (${eroutes}) eroutes exist!"
		fi
		exit 1
	fi
	# todo: ipsec verify --quiet that only shows problems
	#/usr/sbin/ipsec verify;
	#exit $?;
	exit 4
	;;

  --version)
	if test " $IPSEC_setupflags" != " "
	then
		echo "$me $1 does not support $IPSEC_setupflags"
		exit 1
	fi

	echo "$me $IPSEC_VERSION"
	exit 0
	;;

  --help)
	if test " $IPSEC_setupflags" != " "
	then
		echo "$me $1 does not support $IPSEC_setupflags"
		exit 1
	fi

	echo "Usage: $me {--start|--stop|--restart|--status}"
	exit 0
	;;

  *)
	echo "Usage: $me {--start|--stop|--restart|--status}" >&2
	exit 2
esac

exit 0