// Spectre Samba Mounter // // Douglas Thrift // // $Id: Configurator.cpp,v 1.8 2003/07/31 00:56:29 douglas Exp $ #include "Configurator.h" Configurator::Configurator(const string& host) { this->host = host; good = configurate(); } string Configurator::password(const string& user) { string password; for (unsigned index = 0; index < passwd.size(); index++) { switch (passwd[index]) { case file: { string file = config.install + "/conf/private/" + host + "." + user; ifstream fin(file.c_str()); if (fin.is_open()) { getline(fin, password); } } break; case prompt: { string prompt = user + "@" + host + "\'s password:"; password = getpass(prompt.c_str()); } break; default: // break; } if (password == "") { continue; } else { break; } } return password; } bool Configurator::configurate() { if (config.hosts.count(host) < 2) { cerr << program << ": " << host << ": No configuration\n"; return false; } for (multimap::iterator itor = config.hosts.lower_bound(host); itor != config.hosts.upper_bound(host); itor++) { string entry = itor->second; if (entry.find("passwd=") == 0) { istringstream sin(entry.substr(7)); do { string item; getline(sin, item, ','); if (item == "file") { passwd.push_back(file); } else if (item == "prompt") { passwd.push_back(prompt); } } while (sin.good()); } else if (entry.find("folder=") == 0) { istringstream sin(entry.substr(7)); string folder; getline(sin, folder, ':'); string local; getline(sin, local, ':'); string remote; getline(sin, remote); if (folder == "*") { regular.local = local; regular.remote = remote; } else { Folder special; special.local = local; special.remote = remote; folders.insert(pair(folder, special)); } } else { cerr << program << ": " << entry << ": Unknown configuration\n"; } } if (passwd.size() == 0) { cerr << program << ": " << host << ": No passwd configuration\n"; return false; } if (regular.local == "" || regular.remote == "") { cerr << program << ": " << host << ": No * folder configuration\n"; return false; } if (debug) { cerr << "host = " << host << "\n" << "passwd = {\n"; for (unsigned index = 0; index < passwd.size(); index++) { cerr << " [" << index << "] = "; switch (passwd[index]) { case file: cerr << "file"; break; case prompt: cerr << "prompt"; break; default: cerr << passwd[index]; break; } cerr << "\n"; } cerr << "}\n" << "regular = {\n" << " local = " << regular.local << "\n" << " remote = " << regular.remote << "\n" << "}\n" << "folders = {\n"; for (map::iterator itor = folders.begin(); itor != folders.end(); itor++) { cerr << " " << itor->first << " = {\n" << " local = " << itor->second.local << "\n" << " remote = " << itor->second.remote << "\n" << " }\n"; } cerr << "}\n"; } return true; }