- Fixed compile on Windows. Added new type "rs_lock_handle_t" for file locking functions.

- Added missing check of file pointer in PGPHandler::decryptTextFromFile
- Added missing fclose of the ssl passphrase file in RsLoginHandler::getSSLPasswdFromGPGFile. Is this still needed, because PGPHandler::decryptTextFromFile does the same check?
- Fixed possible memory leak in ops_decrypt_memory.

git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-OpenPGP@5222 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
thunder2 2012-06-14 22:53:02 +00:00
parent dba66cdd7a
commit f50edd228f
6 changed files with 22 additions and 16 deletions

View File

@ -509,6 +509,11 @@ bool PGPHandler::decryptTextFromFile(const PGPIdType& key_id,std::string& text,c
FILE *f = fopen(inputfile.c_str(),"rb") ; FILE *f = fopen(inputfile.c_str(),"rb") ;
if (f == NULL)
{
return false;
}
char c ; char c ;
while( (c = getc(f))!= EOF) while( (c = getc(f))!= EOF)
buf += c; buf += c;
@ -522,6 +527,7 @@ bool PGPHandler::decryptTextFromFile(const PGPIdType& key_id,std::string& text,c
ops_boolean_t res = ops_decrypt_memory((const unsigned char *)buf.c_str(),buf.length(),&out_buf,&out_length,_secring,ops_true,cb_get_passphrase) ; ops_boolean_t res = ops_decrypt_memory((const unsigned char *)buf.c_str(),buf.length(),&out_buf,&out_length,_secring,ops_true,cb_get_passphrase) ;
text = std::string((char *)out_buf,out_length) ; text = std::string((char *)out_buf,out_length) ;
free (out_buf);
return (bool)res ; return (bool)res ;
} }

View File

@ -93,11 +93,7 @@ class RsInitConfig
/* for certificate creation */ /* for certificate creation */
//static std::string gpgPasswd; //static std::string gpgPasswd;
#ifndef WINDOWS_SYS static rs_lock_handle_t lockHandle;
static int lockHandle;
#else
static HANDLE lockHandle;
#endif
/* These fields are needed for login */ /* These fields are needed for login */
static std::string loginId; static std::string loginId;
@ -152,11 +148,7 @@ static const int SSLPWD_LEN = 64;
std::list<accountId> RsInitConfig::accountIds; std::list<accountId> RsInitConfig::accountIds;
std::string RsInitConfig::preferedId; std::string RsInitConfig::preferedId;
#ifndef WINDOWS_SYS rs_lock_handle_t RsInitConfig::lockHandle;
int RsInitConfig::lockHandle;
#else
HANDLE RsInitConfig::lockHandle;
#endif
std::string RsInitConfig::configDir; std::string RsInitConfig::configDir;
std::string RsInitConfig::load_cert; std::string RsInitConfig::load_cert;

View File

@ -684,6 +684,7 @@ bool RsLoginHandler::getSSLPasswdFromGPGFile(const std::string& ssl_id,std::stri
std::cerr << "No password provided, and no sslPassphraseFile : " << getSSLPasswdFileName(ssl_id).c_str() << std::endl; std::cerr << "No password provided, and no sslPassphraseFile : " << getSSLPasswdFileName(ssl_id).c_str() << std::endl;
return 0; return 0;
} }
fclose(sslPassphraseFile);
std::cerr << "opening sslPassphraseFile : " << getSSLPasswdFileName(ssl_id).c_str() << std::endl; std::cerr << "opening sslPassphraseFile : " << getSSLPasswdFileName(ssl_id).c_str() << std::endl;

View File

@ -852,7 +852,7 @@ std::string RsDirUtil::makePath(const std::string &path1, const std::string &pat
return path; return path;
} }
int RsDirUtil::createLockFile(const std::string& lock_file_path,int& lock_handle) int RsDirUtil::createLockFile(const std::string& lock_file_path, rs_lock_handle_t &lock_handle)
{ {
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
@ -926,7 +926,7 @@ int RsDirUtil::createLockFile(const std::string& lock_file_path,int& lock_handle
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
} }
void RsDirUtil::releaseLockFile(int lockHandle) void RsDirUtil::releaseLockFile(rs_lock_handle_t lockHandle)
{ {
/******************************** WINDOWS/UNIX SPECIFIC PART ******************/ /******************************** WINDOWS/UNIX SPECIFIC PART ******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS

View File

@ -36,6 +36,13 @@ class RsThread;
#include <retroshare/rstypes.h> #include <retroshare/rstypes.h>
#ifndef WINDOWS_SYS
typedef int rs_lock_handle_t;
#else
#include "rswin.h"
typedef HANDLE rs_lock_handle_t;
#endif
// This is a scope guard on a given file. Works like a mutex. Is blocking. // This is a scope guard on a given file. Works like a mutex. Is blocking.
// We could do that in another way: derive RsMutex into RsLockFileMutex, and // We could do that in another way: derive RsMutex into RsLockFileMutex, and
// use RsStackMutex on it transparently. Only issue: this will cost little more // use RsStackMutex on it transparently. Only issue: this will cost little more
@ -48,7 +55,7 @@ class RsStackFileLock
~RsStackFileLock() ; ~RsStackFileLock() ;
private: private:
int _file_handle ; rs_lock_handle_t _file_handle ;
}; };
namespace RsDirUtil { namespace RsDirUtil {
@ -90,10 +97,10 @@ Sha1CheckSum sha1sum(uint8_t *data,uint32_t size) ;
// 0: Success // 0: Success
// 1: Another instance already has the lock // 1: Another instance already has the lock
// 2 : Unexpected error // 2 : Unexpected error
int createLockFile(const std::string& lock_file_path,int& lock_handle) ; int createLockFile(const std::string& lock_file_path, rs_lock_handle_t& lock_handle) ;
// Removes the lock file with specified handle. // Removes the lock file with specified handle.
void releaseLockFile(int lockHandle) ; void releaseLockFile(rs_lock_handle_t lockHandle) ;
std::wstring getWideTopDir(std::wstring); std::wstring getWideTopDir(std::wstring);
std::wstring getWideRootDir(std::wstring); std::wstring getWideRootDir(std::wstring);

View File

@ -308,7 +308,7 @@ ops_boolean_t ops_decrypt_memory(const unsigned char *encrypted_memory,int em_le
// setup memory chunk // setup memory chunk
ops_memory_t *output_mem = ops_memory_new() ; ops_memory_t *output_mem;
ops_setup_memory_write(&pinfo->cbinfo.cinfo, &output_mem,0) ; ops_setup_memory_write(&pinfo->cbinfo.cinfo, &output_mem,0) ;