This file is indexed.

/usr/sbin/fence_ipmilan is in fence-agents 4.0.25-2ubuntu1.

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
#!/usr/bin/python -tt

import sys, re, os
import atexit
from pipes import quote
sys.path.append("/usr/share/fence")
from fencing import *
from fencing import fail_usage, is_executable, run_command, run_delay

#BEGIN_VERSION_GENERATION
RELEASE_VERSION="4.0.25"
BUILD_DATE="(built Sat, 10 Feb 2018 00:55:27 -0800)"
REDHAT_COPYRIGHT="Copyright (C) Red Hat, Inc. 2004-2010 All rights reserved."
#END_VERSION_GENERATION

def get_power_status(_, options):
	output = _run_command(options, "status")
	match = re.search('[Cc]hassis [Pp]ower is [\\s]*([a-zA-Z]{2,3})', str(output))
	status = match.group(1) if match else None
	return status

def set_power_status(_, options):
	_run_command(options, options["--action"])
	return

def reboot_cycle(_, options):
	output = _run_command(options, "cycle")
	return bool(re.search('chassis power control: cycle', str(output).lower()))

def reboot_diag(_, options):
	output = _run_command(options, "diag")
	return bool(re.search('chassis power control: diag', str(output).lower()))

def _run_command(options, action):
	cmd, log_cmd = create_command(options, action)
	return run_command(options, cmd, log_command=log_cmd)

def create_command(options, action):
	class Cmd:
		cmd = ""
		log = ""

		@classmethod
		def append(cls, cmd, log=None):
			cls.cmd += cmd
			cls.log += (cmd if log is None else log)

	# --use-sudo / -d
	if "--use-sudo" in options:
		Cmd.append(options["--sudo-path"] + " ")

	Cmd.append(options["--ipmitool-path"])

	# --lanplus / -L
	if "--lanplus" in options and options["--lanplus"] in ["", "1"]:
		Cmd.append(" -I lanplus")
	else:
		Cmd.append(" -I lan")
	# --ip / -a
	Cmd.append(" -H " + options["--ip"])

	# --username / -l
	if "--username" in options and len(options["--username"]) != 0:
		Cmd.append(" -U " + quote(options["--username"]))

	# --auth / -A
	if "--auth" in options:
		Cmd.append(" -A " + options["--auth"])

	# --password / -p
	if "--password" in options:
		Cmd.append(" -P " + quote(options["--password"]), " -P [set]")
	else:
		Cmd.append(" -P ''", " -P [set]")

	# --cipher / -C
	if "--cipher" in options:
		Cmd.append(" -C " + options["--cipher"])

	# --port / -n
	if "--ipport" in options:
		Cmd.append(" -p " + options["--ipport"])

	if "--privlvl" in options:
		Cmd.append(" -L " + options["--privlvl"])

	# --action / -o
	Cmd.append(" chassis power " + action)

	return (Cmd.cmd, Cmd.log)

def define_new_opts():
	all_opt["lanplus"] = {
		"getopt" : "P",
		"longopt" : "lanplus",
		"help" : "-P, --lanplus                  Use Lanplus to improve security of connection",
		"required" : "0",
		"default" : "0",
		"shortdesc" : "Use Lanplus to improve security of connection",
		"order": 1
	}
	all_opt["auth"] = {
		"getopt" : "A:",
		"longopt" : "auth",
		"help" : "-A, --auth=[auth]              IPMI Lan Auth type (md5|password|none)",
		"required" : "0",
		"shortdesc" : "IPMI Lan Auth type.",
		"choices" : ["md5", "password", "none"],
		"order": 1
	}
	all_opt["cipher"] = {
		"getopt" : "C:",
		"longopt" : "cipher",
		"help" : "-C, --cipher=[cipher]          Ciphersuite to use (same as ipmitool -C parameter)",
		"required" : "0",
		"shortdesc" : "Ciphersuite to use (same as ipmitool -C parameter)",
		"order": 1
	}
	all_opt["privlvl"] = {
		"getopt" : "L:",
		"longopt" : "privlvl",
		"help" : "-L, --privlvl=[level]          "
				"Privilege level on IPMI device (callback|user|operator|administrator)",
		"required" : "0",
		"shortdesc" : "Privilege level on IPMI device",
		"default" : "administrator",
		"choices" : ["callback", "user", "operator", "administrator"],
		"order": 1
	}
	all_opt["ipmitool_path"] = {
		"getopt" : ":",
		"longopt" : "ipmitool-path",
		"help" : "--ipmitool-path=[path]         Path to ipmitool binary",
		"required" : "0",
		"shortdesc" : "Path to ipmitool binary",
		"default" : "/usr/bin/ipmitool",
		"order": 200
	}

def main():
	atexit.register(atexit_handler)

	device_opt = ["ipaddr", "login", "no_login", "no_password", "passwd", "diag",
		"lanplus", "auth", "cipher", "privlvl", "sudo", "ipmitool_path", "method"]
	define_new_opts()

	all_opt["power_wait"]["default"] = 2
	if os.path.basename(sys.argv[0]) == "fence_ilo3":
		all_opt["power_wait"]["default"] = "4"
		all_opt["method"]["default"] = "cycle"
		all_opt["lanplus"]["default"] = "1"
	elif os.path.basename(sys.argv[0]) == "fence_ilo4":
		all_opt["lanplus"]["default"] = "1"

	all_opt["ipport"]["default"] = "623"
	all_opt["method"]["help"] = "-m, --method=[method]          Method to fence (onoff|cycle) (Default: cycle)\n" \
				    "WARNING! This fence agent might report success before the node is powered off. " \
				    "You should use -m/method onoff if your fence device works correctly with that option."

	options = check_input(device_opt, process_input(device_opt))

	docs = {}
	docs["shortdesc"] = "Fence agent for IPMI"
	docs["longdesc"] = "fence_ipmilan is an I/O Fencing agent\
which can be used with machines controlled by IPMI.\
This agent calls support software ipmitool (http://ipmitool.sf.net/). \
WARNING! This fence agent might report success before the node is powered off. \
You should use -m/method onoff if your fence device works correctly with that option."
	docs["vendorurl"] = ""
	docs["symlink"] = [("fence_ilo3", "Fence agent for HP iLO3"),
		("fence_ilo4", "Fence agent for HP iLO4"),
		("fence_imm", "Fence agent for IBM Integrated Management Module"),
		("fence_idrac", "Fence agent for Dell iDRAC")]
	show_docs(options, docs)

	run_delay(options)

	if not is_executable(options["--ipmitool-path"]):
		fail_usage("Ipmitool not found or not accessible")

	reboot_fn = reboot_cycle
	if options["--action"] == "diag":
		# Diag is a special action that can't be verified so we will reuse reboot functionality
		# to minimize impact on generic library
		options["--action"] = "reboot"
		options["--method"] = "cycle"
		reboot_fn = reboot_diag

	result = fence_action(None, options, set_power_status, get_power_status, None, reboot_fn)
	sys.exit(result)

if __name__ == "__main__":
	main()