From: Micke Nordin Date: Sun, 24 Jan 2010 10:58:47 +0000 (+0100) Subject: updating with fix for desktop/laptop use X-Git-Url: http://git.maemo.org/git/?p=mnenc;a=commitdiff_plain;h=refs%2Fheads%2Fmaster updating with fix for desktop/laptop use --- diff --git a/libmnenc/mnenc.cpp b/libmnenc/mnenc.cpp index 0e162da..c2a414b 100644 --- a/libmnenc/mnenc.cpp +++ b/libmnenc/mnenc.cpp @@ -6,6 +6,7 @@ #include #include #include + #include "mnenc.hpp" using namespace std; @@ -69,8 +70,7 @@ string mnenc::genkey() { for(int i = 0; i < 15; i++) { key += (rand() % 10); //generate a random number between 0 and 9 } - string username = getenv("USER"); //Get username - string filename = "/home/" + username + "/.mnenc/.keyfile"; //This is where the key goes + string filename = make_path() + ".keyfile"; //This is where the key goes ofstream os; os.open(filename.c_str()); if(os.is_open()) { @@ -85,16 +85,17 @@ void mnenc::get_imei() { */ string username = getenv("USER"); //Get username - string filename = "/home/" + username + "/.mnenc/.keyfile"; //This is where the key goes if we generate it + string filename = make_path() + ".keyfile"; //This is where the key goes if we generate it string cmd = "dbus-send --system --print-reply --type=method_call --dest=com.nokia.phone.SIM /com/nokia/phone/SIM/security Phone.Sim.Security.get_imei | grep string | sed -e 's/^.*\\\"\\([0-9]\\)/\\1/' -e 's/\\\"//'"; //Command used when shelling out to get imei - if(system(cmd.c_str()) == 0) { //if we can get imei from dbus - FILE *fp; //a file pointer - char buffer[1024]; //Some tmp storage - fp = popen(cmd.c_str(), "r"); //Open a pipe whith the command - while ( fgets(buffer, 1024, fp) != NULL ) //Read the result - imei.append(buffer); //Add the result to our attribute - pclose(fp); //Close the pipe - } else { //If we could not get imei + + FILE *fp; //a file pointer + char buffer[1024]; //Some tmp storage + fp = popen(cmd.c_str(), "r"); //Open a pipe whith the command + while ( fgets(buffer, 1024, fp) != NULL ) //Read the result + imei.append(buffer); //Add the result to our attribute + pclose(fp); //Close the pipe + + if(!is_imei(imei)) { //If we could not get imei ifstream keyfile(filename.c_str()); //open the keyfile string k = ""; string line = ""; @@ -149,11 +150,40 @@ string mnenc::get_user() { // Gets username (Added by hexagon 2010-01-17) return user; } -void mnenc::make_folder() { - string username = getenv("USER"); //Get username - string foldername = "/home/" + username + "/.mnenc"; //This is where the key goes - int ret = chdir(foldername.c_str()); +void mnenc::make_folder() { //Create home directory + string dirname = make_path(); + int ret = chdir(dirname.c_str()); if(ret != 0) { - mkdir(foldername.c_str(), 0755); + mkdir(dirname.c_str(), 0755); } } + +bool mnenc::is_int(char c) { //See if a char is an int + return (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9'); +} + +bool mnenc::is_imei(string str) { //See if a string is made up of 15 ints + bool proper_length = false; //Is it 15 chars? + bool is_ints = true; //Is it only ints? + if(str.length() == 15) { //Check length + proper_length = true; + } else { + return false; //Exit early if it fails length test + } + for(int i = 0; i < (signed) str.length(); i++) { //Check if they are all ints + if(!is_int(str[i])) { + is_ints = false; + } + } + if(proper_length && is_ints) { //Return true if it passes the tests + return true; + } else { + return false; //And false if it doesnt + } +} + +string mnenc::make_path() { //Create path to qtify home + string username = getenv("USER"); //Get username + string path = "/home/" + username + "/.qtify/"; //This is home directory of qtify + return path; +} diff --git a/libmnenc/mnenc.hpp b/libmnenc/mnenc.hpp index 5bea13a..b05790f 100644 --- a/libmnenc/mnenc.hpp +++ b/libmnenc/mnenc.hpp @@ -43,8 +43,8 @@ class mnenc { void set_enc(string str) {enc = str;}; //set encrypted password void set_dec(string str) {dec = str;}; //set decrypted password string genkey(); //generate a key to be used instead of imei - void make_folder(); //Create /home/user/.qtify if it doesnt exist - + bool is_int(char c); //see if a char is actualy an int + string make_path(); public: mnenc(); void encrypt(string str); //encrypt password @@ -53,6 +53,8 @@ class mnenc { string get_enc() {return enc;}; //Get encrypted password bool to_file(string filename); //Save to file bool from_file(string filename); //get from file + void make_folder(); //Create /home/user/.qtify if it doesnt exist + bool is_imei(string str); //see if a string passes as an imei /* Added by hexagon */ bool user_to_file(string filename); //Save to file bool user_from_file(string filename); //get from file diff --git a/mnencd b/mnencd new file mode 100755 index 0000000..a257b3a Binary files /dev/null and b/mnencd differ