From ce298e62cf2e7c90fab2fb6ff12f4766ed54c80f Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 8 Feb 2011 12:29:11 +0000 Subject: [PATCH] Added AutoLogin clear for OSX git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4019 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/rsserver/rsloginhandler.cc | 67 +++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/libretroshare/src/rsserver/rsloginhandler.cc b/libretroshare/src/rsserver/rsloginhandler.cc index 4698db395..597ac11a3 100644 --- a/libretroshare/src/rsserver/rsloginhandler.cc +++ b/libretroshare/src/rsserver/rsloginhandler.cc @@ -531,7 +531,71 @@ bool RsLoginHandler::clearAutoLogin(const std::string& ssl_id) std::cerr << "Could not clear gnome keyring passwd for SSLID " << ssl_id << std::endl; return false ; } -#else +#else + #ifdef __APPLE__ + + std::cerr << "clearAutoLogin() OSX Version" << std::endl; + //Call SecKeychainFindGenericPassword to get a password from the keychain: + + void *passwordData = NULL; + UInt32 passwordLength = 0; + const char *userId = ssl_id.c_str(); + UInt32 uidLength = strlen(ssl_id.c_str()); + SecKeychainItemRef itemRef = NULL; + + OSStatus status = SecKeychainFindGenericPassword ( + NULL, // default keychain + 10, // length of service name + "Retroshare", // service name + uidLength, // length of account name + userId, // account name + &passwordLength, // length of password + &passwordData, // pointer to password data + &itemRef // the item reference + ); + + std::cerr << "RsTryAutoLogin() SecKeychainFindGenericPassword returned: " << status << std::endl; + + if (status != 0) + { + std::cerr << "clearAutoLogin() Error Finding password " << std::endl; + + /* error */ + if (status == errSecItemNotFound) + { + //Is password on keychain? + std::cerr << "RsTryAutoLogin() Error - Looks like password is not in KeyChain " << std::endl; + } + } + else + { + std::cerr << "clearAutoLogin() Password found on KeyChain! " << std::endl; + + OSStatus deleteStatus = SecKeychainItemDelete (itemRef); + if (status != 0) + { + std::cerr << "clearAutoLogin() Failed to Delete Password status: " << deleteStatus << std::endl; + } + else + { + std::cerr << "clearAutoLogin() Deleted Password" << std::endl; + } + } + + //Free the data allocated by SecKeychainFindGenericPassword: + + SecKeychainItemFreeContent ( + NULL, //No attribute data to release + passwordData //Release data buffer allocated by SecKeychainFindGenericPassword + ); + + if (itemRef) CFRelease(itemRef); + + return (status == 0); + + /******************** OSX KeyChain stuff *****************************/ + + #else // WINDOWS / Generic Linux. std::string passwdfile = getAutologinFileName(ssl_id) ; @@ -552,6 +616,7 @@ bool RsLoginHandler::clearAutoLogin(const std::string& ssl_id) } return false; + #endif #endif }