- Removed some potentially harmful (deadlock) code.

- Put some printf into debugging #ifdef



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@2784 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-04-25 19:26:37 +00:00
parent a6b5e8c364
commit 78644a2441
2 changed files with 223 additions and 203 deletions

View File

@ -104,7 +104,7 @@ gpg_error_t pgp_pwd_callback(void *hook, const char *uid_hint, const char *passp
} }
AuthGPG::AuthGPG() AuthGPG::AuthGPG()
:gpgmeInit(false),gpgmeKeySelected(false),autorisePasswordCallbackNotify(true),p3Config(CONFIG_TYPE_AUTHGPG) :gpgmeInit(false),gpgmeKeySelected(false),p3Config(CONFIG_TYPE_AUTHGPG)
{ {
{ {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/ RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK); /******* LOCKED ******/
@ -310,7 +310,9 @@ bool AuthGPG::storeAllKeys_locked()
std::cerr << "AuthGPG::storeAllKeys_locked()" << std::endl; std::cerr << "AuthGPG::storeAllKeys_locked()" << std::endl;
#endif #endif
pgpMtx.writeLock(); std::list<std::string> gpg_change_trust_list;
{
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
gpg_error_t ERR; gpg_error_t ERR;
if (!gpgmeInit) if (!gpgmeInit)
@ -357,7 +359,6 @@ bool AuthGPG::storeAllKeys_locked()
mKeyList.clear(); mKeyList.clear();
} }
std::list<std::string> gpg_change_trust_list;
for(int i = 0;GPG_ERR_NO_ERROR == ERR; i++) for(int i = 0;GPG_ERR_NO_ERROR == ERR; i++)
{ {
/* store in pqiAuthDetails */ /* store in pqiAuthDetails */
@ -469,6 +470,11 @@ bool AuthGPG::storeAllKeys_locked()
/* store in map */ /* store in map */
mKeyList[nu.id] = nu; mKeyList[nu.id] = nu;
#ifdef GPG_DEBUG
std::cerr << "nu.name" << nu.name << std::endl;
std::cerr << "nu.trustLvl" << nu.trustLvl << std::endl;
std::cerr << "nu.accept_connection" << nu.accept_connection << std::endl;
#endif
if (nu.trustLvl < 2 && nu.accept_connection) { if (nu.trustLvl < 2 && nu.accept_connection) {
//add it to the list of key that we will force the trust to 2 //add it to the list of key that we will force the trust to 2
gpg_change_trust_list.push_back(nu.id); gpg_change_trust_list.push_back(nu.id);
@ -490,7 +496,7 @@ bool AuthGPG::storeAllKeys_locked()
} }
gpgme_set_keylist_mode(CTX, origmode); gpgme_set_keylist_mode(CTX, origmode);
pgpMtx.writeUnlock(); }
std::list<std::string>::iterator it; std::list<std::string>::iterator it;
for(it = gpg_change_trust_list.begin(); it != gpg_change_trust_list.end(); it++) for(it = gpg_change_trust_list.begin(); it != gpg_change_trust_list.end(); it++)
@ -1284,15 +1290,15 @@ bool AuthGPG::setAcceptToConnectGPGCertificate(std::string gpg_id, bool acceptan
/* reload stuff now ... */ /* reload stuff now ... */
storeAllKeys_locked(); storeAllKeys_locked();
pgpMtx.writeLock(); {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
certmap::iterator it; certmap::iterator it;
if (mKeyList.end() == (it = mKeyList.find(gpg_id))) { if (mKeyList.end() == (it = mKeyList.find(gpg_id))) {
return false; return false;
} }
it->second.accept_connection = acceptance; it->second.accept_connection = acceptance;
mAcceptToConnectMap[gpg_id] = acceptance; mAcceptToConnectMap[gpg_id] = acceptance;
}
pgpMtx.writeUnlock();
storeAllKeys_locked(); storeAllKeys_locked();
IndicateConfigChanged(); IndicateConfigChanged();
@ -1430,7 +1436,9 @@ int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
return 0; return 0;
} }
pgpMtx.writeLock(); {
RsStackReadWriteMutex stack(pgpMtx, RsReadWriteMutex::WRITE_LOCK);
gpgcert trustCert = mKeyList.find(id)->second; gpgcert trustCert = mKeyList.find(id)->second;
gpgme_key_t trustKey = trustCert.key; gpgme_key_t trustKey = trustCert.key;
std::string trustString; std::string trustString;
@ -1451,7 +1459,7 @@ int AuthGPG::privateTrustCertificate(std::string id, int trustlvl)
//the key ref has changed, we got to get rid of the old reference. //the key ref has changed, we got to get rid of the old reference.
trustCert.key = NULL; trustCert.key = NULL;
pgpMtx.writeUnlock(); }
storeAllKeys_locked(); storeAllKeys_locked();
@ -1600,6 +1608,7 @@ static std::string setKeyPairParams(bool useRsa, unsigned int blen,
* from the keyring * from the keyring
*/ */
#ifdef UNUSED_CODE
static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment, std::string email) { static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment, std::string email) {
gpgme_key_t key; gpgme_key_t key;
@ -1643,6 +1652,7 @@ static gpgme_key_t getKey(gpgme_ctx_t CTX, std::string name, std::string comment
} }
return NULL; return NULL;
} }
#endif
/* Callback function for key signing */ /* Callback function for key signing */
@ -1653,7 +1663,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
class EditParams *params = (class EditParams *)opaque; class EditParams *params = (class EditParams *)opaque;
class SignParams *sparams = (class SignParams *)params->oParams; class SignParams *sparams = (class SignParams *)params->oParams;
const char *result = NULL; const char *result = NULL;
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback status: %d args: %s, params->state: %d\n", status, args, params->state); fprintf(stderr,"keySignCallback status: %d args: %s, params->state: %d\n", status, args, params->state);
/* printf stuff out */ /* printf stuff out */
@ -1695,6 +1705,7 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
fprintf(stderr,"keySignCallback params->state SIGN_ENTER_PASSPHRASE\n"); fprintf(stderr,"keySignCallback params->state SIGN_ENTER_PASSPHRASE\n");
if (params->state == SIGN_ERROR) if (params->state == SIGN_ERROR)
fprintf(stderr,"keySignCallback params->state SIGN_ERROR"); fprintf(stderr,"keySignCallback params->state SIGN_ERROR");
#endif
if(status == GPGME_STATUS_EOF || if(status == GPGME_STATUS_EOF ||
@ -1714,7 +1725,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
switch (params->state) switch (params->state)
{ {
case SIGN_START: case SIGN_START:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_START\n"); fprintf(stderr,"keySignCallback SIGN_START\n");
#endif
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args))) (!std::string("keyedit.prompt").compare(args)))
@ -1729,7 +1742,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_COMMAND: case SIGN_COMMAND:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_COMMAND\n"); fprintf(stderr,"keySignCallback SIGN_COMMAND\n");
#endif
if (status == GPGME_STATUS_GET_BOOL && if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("keyedit.sign_all.okay").compare(args))) (!std::string("keyedit.sign_all.okay").compare(args)))
@ -1775,7 +1790,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_UIDS: case SIGN_UIDS:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_UIDS\n"); fprintf(stderr,"keySignCallback SIGN_UIDS\n");
#endif
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&
(!std::string("sign_uid.expire").compare(args))) (!std::string("sign_uid.expire").compare(args)))
@ -1809,7 +1826,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_SET_EXPIRE: case SIGN_SET_EXPIRE:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_SET_EXPIRE\n"); fprintf(stderr,"keySignCallback SIGN_SET_EXPIRE\n");
#endif
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&
(!std::string("sign_uid.class").compare(args))) (!std::string("sign_uid.class").compare(args)))
@ -1824,7 +1843,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_SET_CHECK_LEVEL: case SIGN_SET_CHECK_LEVEL:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_SET_CHECK_LEVEL\n"); fprintf(stderr,"keySignCallback SIGN_SET_CHECK_LEVEL\n");
#endif
if (status == GPGME_STATUS_GET_BOOL && if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("sign_uid.okay").compare(args))) (!std::string("sign_uid.okay").compare(args)))
@ -1839,7 +1860,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_ENTER_PASSPHRASE: case SIGN_ENTER_PASSPHRASE:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n"); fprintf(stderr,"keySignCallback SIGN_ENTER_PASSPHRASE\n");
#endif
if (status == GPGME_STATUS_GOOD_PASSPHRASE) if (status == GPGME_STATUS_GOOD_PASSPHRASE)
{ {
@ -1852,7 +1875,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_CONFIRM: case SIGN_CONFIRM:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_CONFIRM\n"); fprintf(stderr,"keySignCallback SIGN_CONFIRM\n");
#endif
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args))) (!std::string("keyedit.prompt").compare(args)))
@ -1867,7 +1892,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_QUIT: case SIGN_QUIT:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_QUIT\n"); fprintf(stderr,"keySignCallback SIGN_QUIT\n");
#endif
if (status == GPGME_STATUS_GET_BOOL && if (status == GPGME_STATUS_GET_BOOL &&
(!std::string("keyedit.save.okay").compare(args))) (!std::string("keyedit.save.okay").compare(args)))
@ -1882,7 +1909,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
} }
break; break;
case SIGN_ERROR: case SIGN_ERROR:
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback SIGN_ERROR\n"); fprintf(stderr,"keySignCallback SIGN_ERROR\n");
#endif
if (status == GPGME_STATUS_GET_LINE && if (status == GPGME_STATUS_GET_LINE &&
(!std::string("keyedit.prompt").compare(args))) (!std::string("keyedit.prompt").compare(args)))
@ -1904,7 +1933,9 @@ static gpg_error_t keySignCallback(void *opaque, gpgme_status_code_t status, \
if (result) if (result)
{ {
#ifdef GPG_DEBUG
fprintf(stderr,"keySignCallback result:%s\n", result); fprintf(stderr,"keySignCallback result:%s\n", result);
#endif
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
if (*result) if (*result)
{ {
@ -1941,6 +1972,7 @@ static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
const char *result = NULL; const char *result = NULL;
/* printf stuff out */ /* printf stuff out */
#ifdef GPG_DEBUG
if (status == GPGME_STATUS_EOF) if (status == GPGME_STATUS_EOF)
fprintf(stderr,"keySignCallback GPGME_STATUS_EOF\n"); fprintf(stderr,"keySignCallback GPGME_STATUS_EOF\n");
if (status == GPGME_STATUS_GOT_IT) if (status == GPGME_STATUS_GOT_IT)
@ -1973,6 +2005,7 @@ static gpgme_error_t trustCallback(void *opaque, gpgme_status_code_t status, \
fprintf(stderr,"keySignCallback params->state TRUST_QUIT\n"); fprintf(stderr,"keySignCallback params->state TRUST_QUIT\n");
if (params->state == TRUST_ERROR) if (params->state == TRUST_ERROR)
fprintf(stderr,"keySignCallback params->state TRUST_ERROR\n"); fprintf(stderr,"keySignCallback params->state TRUST_ERROR\n");
#endif
if(status == GPGME_STATUS_EOF || if(status == GPGME_STATUS_EOF ||
@ -2159,11 +2192,3 @@ bool AuthGPG::loadList(std::list<RsItem*> load)
return true; return true;
} }
void AuthGPG::setAutorisePasswordCallbackNotify(bool autorise) {
autorisePasswordCallbackNotify = autorise;
return;
}
bool AuthGPG::getAutorisePasswordCallbackNotify() {
return autorisePasswordCallbackNotify;
}

View File

@ -130,9 +130,6 @@ class AuthGPG : public p3Config
bool printKeys(); bool printKeys();
void setAutorisePasswordCallbackNotify(bool);
bool getAutorisePasswordCallbackNotify();
/*********************************************************************************/ /*********************************************************************************/
/************************* STAGE 1 ***********************************************/ /************************* STAGE 1 ***********************************************/
/*********************************************************************************/ /*********************************************************************************/
@ -253,8 +250,6 @@ private:
bool gpgmeKeySelected; bool gpgmeKeySelected;
bool autorisePasswordCallbackNotify;
gpgme_engine_info_t INFO; gpgme_engine_info_t INFO;
gpgme_ctx_t CTX; gpgme_ctx_t CTX;