#include "ConfigFile.h" string StripWhitespace(string strInput) { string temp = strInput; //strip the front for(int i=0; i < (int)strInput.length(); i++) { if (char(strInput[i]) == 9 || char(strInput[i]) == 32) { temp.erase(0,1); } else { break; } } //strip the back int count = (int)temp.length(); for(int i=count; i > 0;) { i--; if (char(strInput[i]) == 9 || char(strInput[i]) == 32) { temp.erase(i,1); } else { break; } } return temp; } bool ConfigFile::FileExists() { ifstream inp; inp.open(File.c_str(), ifstream::in); inp.close(); if(inp.fail()) { return false; } else { return true; } } string ConfigFile::GetValue(string Key) { map<string, string>::const_iterator it; it = Settings.find(Key); if (it != Settings.end()) { return it->second; } else { throw 1; //not a valid setting } } void ConfigFile::ReadSettings() { ifstream inp; string line = ""; inp.open(File.c_str(), ifstream::in); while (getline(inp, line)) { //for each line in config file if (!line.empty() && line.c_str()[0] != '#' && line.find("=") != string::npos) { //get possible variable int point = int(line.find("=")); string first = StripWhitespace(line.substr(0,point)); string second = StripWhitespace(line.substr(point+1)); Settings.insert(pair<string, string>(first, second)); } line = ""; } } void ConfigFile::WriteDefault() { string config = GetDefault(); ofstream out; out.open(File.c_str(), ofstream::out); out.write(config.c_str(), (int)config.length()); out.close(); } void ConfigFile::setup() { if (File == "") { File = GetFilename(); } if (FileExists()) { ReadSettings(); } else { WriteDefault(); ReadSettings(); } } void ConfigFile::AddValue(string Key, string Value) { Settings.insert(pair<string, string>(Key, Value)); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 7332 | Nick Poole |
Preliminary version of AuthCheck A multi-stage authentication application for use as an authentication trigger. Currently only tested against an LDAP server without TLS and against a flat file with plain-text passwords. (Under Windows XP). ToDo: Test against TLS enabled LDAP. Test against AD's LDAP interface. Test build on *nix. Add MD5 hashed flat file mode. Add DB modes (SQLite, MySQL, etc). |