#include "AuthCheck.h" int main(int argc, char **argv) { char Password[128]; int authed = 1; //false AuthConfig *config; //Check args if( argc < 2 || argc > 3 ) { cerr << "Wrong number of arguments!\n"; cerr << "Usage: authcheck username [ConfigFile]\n"; cerr << "Example: authcheck user1234 authcheck.conf\n"; exit( -1 ); } if(strlen(argv[1]) == 0) { cerr << "Error: NULL user names are not allowed.\n"; exit ( -1 ); } //set up ConfigFile if( argc == 3) { //use set ConfigFile config = new AuthConfig(argv[2]); } else { //default to AuthCheck.conf config = new AuthConfig(); } //Read the password from <stdin> and truncate the newline if( fgets( Password, 128, stdin ) == NULL ) { cerr << "Didn't receive password!\n"; exit( -2 ); } Password[ strlen(Password) - 1 ] = '\0'; //Start the checks int check = 1; string method; bool more = true; while (more) { string key = "Auth-" + num2str(check, 3); try { string authtype = config->GetValue(key + "-type"); if (authtype == "ldap") { try { string authhost = config->GetValue(key + "-host"); string authport = config->GetValue(key + "-port"); string authpattern = config->GetValue(key + "-pattern"); bool authtls = false; if (config->GetValue(key + "-tls") == "true") { authtls = true; } int pos1; if ((pos1 = authpattern.find("%user%")) == string::npos) { throw 1; } else { authpattern.replace(pos1, 6, to_string(argv[1])); } int ret = LDAPCheck((char *)authhost.c_str(), (char *)authport.c_str(), (char *)authpattern.c_str(), Password, authtls); if (ret == 0) //passed { more = false; authed = 0; } else if (ret == -1) //auth user { more = false; } } catch (int e) { cerr << "Error with Auth method: " << num2str(check, 3) << endl; } } if (authtype == "file") { try { string authfile = config->GetValue(key + "-file"); int ret = FileCheck((char *)authfile.c_str(), argv[1], Password); if (ret == 0) //passed { more = false; authed = 0; } else if (ret == -1) //auth user { more = false; } } catch (int e) { cerr << "Error with Auth method: " << num2str(check, 3) << endl; } } } catch (int e) { more = false; } check++; } return authed; } string num2str(int num, int len) { string temp = ""; int base = 1; do { base *= 10; } while ((num/base) >= 1); temp += to_string(num % base); while (temp.length() < len) { temp = "0" + temp; } return temp; }
# | 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). |