4 #include <boost/regex.hpp>
5 #include <boost/property_tree/ptree.hpp>
6 #include <boost/property_tree/ini_parser.hpp>
10 int main(int argc, const char ** argv)
12 static const regex regex_ip("\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3}");
13 static const regex regex_user("[a-zA-Z]+");
17 std::cerr << "Usage: " << argv[0] << " <username> <password> <domain> <IP address>" << std::endl;
21 /* Obtain and validate inpit */
22 std::string user = argv[1];
23 std::string password = argv[2];
24 std::string domain = argv[3];
25 std::string ip = argv[4];
27 if (!regex_match(ip, regex_ip)) {
28 std::cerr << "Invalid IP address " << ip << "." << std::endl;
31 if (!regex_match(user, regex_user)) {
32 std::cerr << "Invalid username " << user << "." << std::endl;
36 /* read configuration */
37 property_tree::ptree config;
38 property_tree::ini_parser::read_ini(CONFIG_FILE, config);
39 std::string keyfile = config.get<std::string>("key");
41 /* Check username, password, domain */
42 optional<std::string> correct_password = config.get_optional<std::string>(user+".password");
43 if (!correct_password || *correct_password != password) {
44 std::cerr << "Username or password incorrect." << std::endl;
47 if (config.get<std::string>(user+".domain") != domain) {
48 std::cerr << "Domain incorrect." << std::endl;
52 std::cout << "It's all right, using key " << keyfile << std::endl;