From b6d9fa3d29a5f5bccd6d475a4b15af0812d19a35 Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Wed, 4 Jun 2014 23:14:44 +0300 Subject: [PATCH] Added --auth-by. --- projects/sgconf/users.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/projects/sgconf/users.cpp b/projects/sgconf/users.cpp index ca555a11..8ee4a3f3 100644 --- a/projects/sgconf/users.cpp +++ b/projects/sgconf/users.cpp @@ -268,6 +268,21 @@ if (!result) PrintUser(info); } +void AuthByCallback(bool result, + const std::string & reason, + const std::vector & info, + void * /*data*/) +{ +if (!result) + { + std::cerr << "Failed to get authorizer list. Reason: '" << reason << "'." << std::endl; + return; + } +std::cout << "Authorized by:\n"; +for (size_t i = 0; i < info.size(); ++i) + std::cout << Indent(1, true) << info[i] << "\n"; +} + bool GetUsersFunction(const SGCONF::CONFIG & config, const std::string & /*arg*/, const std::map & /*options*/) @@ -424,6 +439,19 @@ STG::SERVCONF proto(config.server.data(), return proto.SendMessage(logins, text, SimpleCallback, NULL) == STG::st_ok; } +bool AuthByFunction(const SGCONF::CONFIG & config, + const std::string & arg, + const std::map & /*options*/) +{ +STG::SERVCONF proto(config.server.data(), + config.port.data(), + config.localAddress.data(), + config.localPort.data(), + config.userName.data(), + config.userPass.data()); +return proto.AuthBy(arg, AuthByCallback, NULL) == STG::st_ok; +} + } // namespace anonymous void SGCONF::AppendUsersOptionBlock(COMMANDS & commands, OPTION_BLOCKS & blocks) @@ -436,5 +464,6 @@ blocks.Add("User management options") .Add("del-user", SGCONF::MakeAPIAction(commands, "", DelUserFunction), "delete user") .Add("chg-user", SGCONF::MakeAPIAction(commands, "", params, ChgUserFunction), "change user") .Add("check-user", SGCONF::MakeAPIAction(commands, "", GetCheckParams(), CheckUserFunction), "check user existance and credentials") - .Add("send-message", SGCONF::MakeAPIAction(commands, GetMessageParams(), SendMessageFunction), "send message"); + .Add("send-message", SGCONF::MakeAPIAction(commands, GetMessageParams(), SendMessageFunction), "send message") + .Add("auth-by", SGCONF::MakeAPIAction(commands, "", AuthByFunction), "a list of authorizers user authorized by"); } -- 2.43.2