Previous Topic: BFC 3.5.x Passphrase Check ScriptsNext Topic: BFC: Correcting Issues Booting from pxe


check_passphrase_specify_file

#!/usr/bin/env escript

%% -*- erlang -*-

main([Phrase]) ->

register(bfc_initsrv, self()),

catch package_manager:add_paths([base]),

case repl_check_path() of

none ->

io:fwrite("ERROR: no replica found -- check file unavailable.~n"),

halt(1);

Path ->

check_phrase_against_file(Phrase, Path)

end;

main([Phrase, Path]) ->

register(bfc_initsrv, self()),

catch package_manager:add_paths([base]),

check_phrase_against_file(Phrase, Path);

main(_) ->

usage().

usage() ->

io:format("usage: check_passphrase <passphrase> [<check file>]~n"),

halt(1).

check_phrase_against_file(Phrase, Path) ->

case encrypted_data_driver:checkPassPhrase(

slap_encode(Phrase), Path) of

{error, _} ->

io:fwrite("ERROR: incorrect passphrase.~n"),

halt(1);

ok ->

io:fwrite("Passphrase is correct.~n"),

halt(0)

end.

slap_encode(Phrase) ->

string:strip(os:cmd("slappasswd -s '" ++ Phrase ++ "' -h '{SHA}'"),

both,

$\n).

repl_check_path() ->

try

{ok, [Apps]} = file:consult("/etc/bfc/conf/components.config"),

{components, Parms} = lists:keyfind(components, 1, Apps),

{replpaths, Repls} = lists:keyfind(replpaths, 1, Parms),

case Repls of

[Repl|_] -> filename:join(Repl, "repl.check");

_ -> none

end

catch

_:_ ->

none

end.