/usr/sbin/ekeydctl is in ekeyd 1.1.5-6.
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 | #!/usr/bin/env lua5.1
-- -*- Lua -*-
require "socket"
-- Try to load the UNIX domain sockets support
pcall(function()
require "socket.unix"
end)
function usage()
io.stderr:write((([[
%1%: Control the entropy daemon.
Usage: %1% <command> [args...]
Where command is one of:
add Add an entropy key (dev node provided as argument).
addall Add a directory full of keys (dir name provided as argument).
remove Remove an entropy key (One of dev node, serial, ID as argument).
list List all the entropy keys attached to the daemon.
stats Show the statistics for an entropy key (One of dev node,
serial, ID as argument).
keyring Load a keyring (keyring filename provided as argument)
shutdown Shut the entropy key daemon down.
]]):gsub("%%(%d+)%%", function(n) return ({arg[0]})[tonumber(n)] end)))
end
-- Utility functions
do
local strfind = string.find
local strlen = string.len
local tinsert = table.insert
local strsub = string.sub
function split(s, b, c)
--[[
Return the elements of a delimited string.
Split string \s on boundary \b and return the list of components.
@param s(string) The string to split up
@param b(string) The boundary to split on
@param c(boolean) Correctness. If true, splitting '' returns {''}
@return bits(table) The bits of \s split up on \b
]]
local t = {}
b = b or " "
local p = strfind(s, b, 1, 1)
local l = strlen(b)
if (not p) then
if( s ~= "" or c ) then
return { s }
else
return {}
end
end
while strlen(s) ~= 0 do
p = strfind(s, b, 1, 1)
if (p) then
tinsert(t, strsub(s, 1, p - 1))
s = strsub(s, p + l, -1)
else
tinsert(t, s)
s = ""
end
end
return t
end
end
-- Connectivity
local __tcpcontrolport, __unixcontrolpath = nil, nil
local __socket
function wait_for(pattern)
-- Read lines from the socket (max 3s pause) until we hit pattern.
-- Return a table of all the lines, incl. the one which matches.
-- On timeout, simply report the error and exit.
local rett = {}
local lastline
repeat
lastline = assert(__socket:receive())
rett[#rett + 1] = lastline
if string.match(lastline, "^ERROR") then
io.stderr:write(lastline .. "\n")
os.exit(4)
end
until string.match(lastline, pattern)
return rett
end
function connect_to_daemon()
if __unixcontrolpath then
__socket = socket.unix()
local result, msg = __socket:connect(__unixcontrolpath)
if not result then
error("Unable to connect to ekeyd at " .. __unixcontrolpath .. " (" .. msg .. ") Is ekeyd running?")
end
elseif __tcpcontrolport then
__socket = socket.tcp()
local result, msg = __socket:connect("127.0.0.1", tonumber(__tcpcontrolport))
if not result then
error("Unable to connect to ekeyd at 127.0.0.1:" .. tostring(__tcpcontrolport) .. " (" .. msg .. ") Is ekeyd running?")
end
else
io.stderr:write("Unable to find control socket\n")
os.exit(3)
end
__socket:settimeout(3)
wait_for("PROTOCOL EKEYD/%d+")
end
function expectarg(argno, val, msg)
if val ~= nil then
return
end
io.stderr:write("Expected argument " .. tostring(argno) .. " missing: " .. msg .. "\n")
os.exit(6)
end
-- Commands
function command_list()
__socket:send("ListEntropyKeys\n")
local res = wait_for("^OK$")
local splits = {}
for _, s in ipairs(res) do
splits[#splits+1] = split(s, "\t")
table.remove(splits[#splits], 1)
end
headers = table.remove(splits, 1)
table.remove(splits, table.getn(splits))
print(table.concat(headers, ","))
for _, ktab in ipairs(splits) do
print(table.concat(ktab, ","))
end
end
function command_stats(node)
expectarg(1, node, "Entropy Key Identifier")
__socket:send("StatEntropyKey(" .. string.format("%q", node) .. ")\n")
local res = wait_for("^OK$")
res[#res] = nil
table.sort(res)
for i, v in ipairs(res) do
v = split(v, "\t")[2]
print(v)
end
end
function command_add(node, optserial)
expectarg(1, node, "Path to Entropy Key")
if optseral == nil then
optserial = "nil"
else
optserial=string.format("%q", optserial)
end
__socket:send("AddEntropyKey(" .. string.format("%q", node) .. "," .. optserial .. ")\n")
wait_for("^OK")
end
function command_remove(node)
expectarg(1, node, "Entropy Key Identifier")
__socket:send("RemoveEntropyKey(" .. string.format("%q", node) .. ")\n")
wait_for("^OK")
end
function command_addall(dir)
expectarg(1, dir, "Path to directory of Entropy Keys")
__socket:send("AddEntropyKeys(" .. string.format("%q", dir) .. ")\n")
wait_for("^OK")
end
function command_keyring(keyring)
expectarg(1, keyring, "Path to keyring file to load")
__socket:send("Keyring(" .. string.format("%q", keyring) .. ")\n")
wait_for("^OK")
end
function command_shutdown()
__socket:send("Shutdown\n")
end
if #arg < 1 then
usage()
os.exit(1)
end
command = arg[1]
cmd = _G["command_" .. command]
cmdargs = {}
k = 2
while arg[k] do
cmdargs[k - 1] = arg[k]
k = k + 1
end
if (cmd == nil) then
io.stderr:write("Unknown command: " .. command .. "\n")
usage()
os.exit(2)
end
-- These functions are to emulate the config file of ekeyd
function SetOutputToKernel() end
function AddEntropyKeys() end
function AddEntropyKey() end
function Keyring() end
function SetOutputToFile() end
function TCPControlSocket(port)
__tcpcontrolport = port
end
function UnixControlSocket(path)
__unixcontrolpath = path
end
function EGDUnixSocket() end
function EGDTCPSocket() end
function Daemonise() end
assert(loadfile"/etc/entropykey/ekeyd.conf")()
function do_it()
connect_to_daemon()
os.exit(cmd(unpack(cmdargs)) or 0)
end
_, msg = xpcall(do_it, function(s) return s end)
-- If we reach here, do_it had an error.
io.stderr:write("Internal error: " .. msg .. "\n")
os.exit(5)
|