Commit 519c1ed6 authored by Nicolas Michon's avatar Nicolas Michon

Use compiled belr grammar for authdb file parsing + make use of new belr utility function

parent 2b53e5d4
Pipeline #1280 passed with stage
in 14 minutes
set(GRAMMAR_FILES
authdb-file-grammar.txt
authdb-file-grammar
)
install(FILES ${GRAMMAR_FILES}
......
LWS = [*WSP CRLF] 1*WSP ; linear whitespace
ILF = [CR] LF ; Linefeed, optional CR
UTF8-CONT = %x80-BF
UTF8-NONASCII = %xC0-DF 1UTF8-CONT
/ %xE0-EF 2UTF8-CONT
/ %xF0-F7 3UTF8-CONT
/ %xF8-Fb 4UTF8-CONT
/ %xFC-FD 5UTF8-CONT
alphanum = ALPHA / DIGIT
token = 1*( alphanum / "-" / "." / "!" / "%" / "*" / "_" / "+" / "`" / "'" / "~" / ":")
user-id = token
phone = token
user = token
domain = token
password = token
ctext = %x21-27 / %x2A-5B / %x5D-7E / UTF8-NONASCII / LWS
comment = "#" *ctext ILF
void = *WSP ILF
version-str = "version:"
version-number = DIGIT
version = version-str version-number ILF
algo = "clrtxt" / "md5" / "sha256"
pass-algo = algo ":" password
identity = user "@" domain
other-userinfo = [*WSP user-id] [*WSP phone] *WSP ILF
auth-line = identity 1*WSP 1*pass-algo 1*WSP ";" *WSP ( ILF / other-userinfo )
password-file = version *(comment / void / auth-line)
......@@ -112,37 +112,34 @@ void FileAuthDb::getPasswordFromBackend(const std::string &id, const std::string
}
shared_ptr<belr::Parser<shared_ptr<FileAuthDbParserElem>>> FileAuthDb::setupParser() {
ABNFGrammarBuilder builder;
string grammarFile = string(BELR_GRAMMARS_DIR) + "/authdb-file-grammar.txt";
shared_ptr<Grammar> grammar = builder.createFromAbnfFile(grammarFile, make_shared<CoreRules>());
string grammarFile = string(BELR_GRAMMARS_DIR) + "/authdb-file-grammar";
shared_ptr<Grammar> grammar = make_shared<Grammar>(grammarFile);
if (!grammar) {
LOGF("Could not build grammar for authdb-file from '%s'", grammarFile.c_str());
if (grammar->load(grammarFile) == -1) {
LOGF("Could not load grammar for authdb-file from '%s'", grammarFile.c_str());
return nullptr;
}
Parser<shared_ptr<FileAuthDbParserElem>> *parser = new Parser<shared_ptr<FileAuthDbParserElem>>(grammar);
std::function<shared_ptr<FileAuthDbParserRoot>()> rootHandlerFunc = std::bind(&make_shared<FileAuthDbParserRoot>);
parser->setHandler("password-file", rootHandlerFunc)
parser->setHandler("password-file", make_fn<FileAuthDbParserRoot>())
->setCollector("version-number", make_sfn(&FileAuthDbParserRoot::setVersion))
->setCollector("auth-line", make_sfn(&FileAuthDbParserRoot::addAuthLine));
std::function<shared_ptr<FileAuthDbParserUserLine>()> authLineHandlerFunc = std::bind(&make_shared<FileAuthDbParserUserLine>);
parser->setHandler("auth-line", authLineHandlerFunc)
parser->setHandler("auth-line", make_fn<FileAuthDbParserUserLine>())
->setCollector("user", make_sfn(&FileAuthDbParserUserLine::setUser))
->setCollector("domain", make_sfn(&FileAuthDbParserUserLine::setDomain))
->setCollector("pass-algo", make_sfn(&FileAuthDbParserUserLine::addPassword))
->setCollector("user-id", make_sfn(&FileAuthDbParserUserLine::setUserId))
->setCollector("phone", make_sfn(&FileAuthDbParserUserLine::setPhone));
std::function<shared_ptr<FileAuthDbParserPassword>()> passwordHandlerFunc = std::bind(&make_shared<FileAuthDbParserPassword>);
parser->setHandler("pass-algo", passwordHandlerFunc)
parser->setHandler("pass-algo", make_fn<FileAuthDbParserPassword>())
->setCollector("algo", make_sfn(&FileAuthDbParserPassword::setAlgo))
->setCollector("password", make_sfn(&FileAuthDbParserPassword::setPassword));
return shared_ptr<Parser<shared_ptr<FileAuthDbParserElem>>>(parser);
}
/*
/*
File parsing using belr with custom grammar for authdb file
*/
void FileAuthDb::sync() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment