From 05884d0f33d39735cfab46f83d5443ceb7c884c4 Mon Sep 17 00:00:00 2001 From: Krista Bennett Date: Fri, 9 Feb 2018 16:32:47 +0100 Subject: [PATCH] ENGINE-360: I *think* this should take care of the no-username problem. --- src/keymanagement.c | 43 ++++++++++++++++----------- src/message_api.c | 30 +++++++++---------- test/new_update_id_and_myself_test.cc | 7 +++-- 3 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/keymanagement.c b/src/keymanagement.c index 906965cf..7182717c 100644 --- a/src/keymanagement.c +++ b/src/keymanagement.c @@ -394,15 +394,18 @@ static PEP_STATUS prepare_updated_identity(PEP_SESSION session, // a DB username, we replace) if (!EMPTYSTR(stored_ident->username)) { if (!EMPTYSTR(return_id->username) && - (strcasecmp(return_id->username, "anonymous") == 0)) { + (strcasecmp(return_id->username, return_id->address) == 0)) { free(return_id->username); - return_id->username = NULL; } if (EMPTYSTR(return_id->username)) { free(return_id->username); return_id->username = strdup(stored_ident->username); } } + else { + if (EMPTYSTR(return_id->username)) + return_id->username = strdup(return_id->address); + } return_id->me = stored_ident->me; @@ -494,8 +497,10 @@ DYNAMIC_API PEP_STATUS update_identity( // if usernames match, we replace the userid. Or if the temp username // is anonymous. + // FIXME: do we need to create an address match function which + // matches the whole dot-and-case rigamarole from if (EMPTYSTR(this_id->username) || - strcasecmp(this_id->username, "anonymous") == 0 || + strcasecmp(this_id->username, this_id->address) == 0 || (identity->username && strcasecmp(identity->username, this_id->username) == 0)) { @@ -541,29 +546,31 @@ DYNAMIC_API PEP_STATUS update_identity( // * else (identity unavailable) else { status = PEP_STATUS_OK; - + + // FIXME: We may need to roll this back. + // FIXME: change docs if we don't // if we only have user_id and address and identity not available // * return error status (identity not found) - if (EMPTYSTR(identity->username)) - status = PEP_CANNOT_FIND_IDENTITY; + if (EMPTYSTR(identity->username)) { + free(identity->username); + identity->username = strdup(identity->address); + } // Otherwise, if we had user_id, address, and username: // * create identity with user_id, address, username // (this is the input id without the fpr + comm type!) - free(identity->fpr); - identity->fpr = NULL; - identity->comm_type = PEP_ct_unknown; - + + if (status == PEP_STATUS_OK) { + elect_pubkey(session, identity); + } + // * We've already checked and retrieved // any applicable temporary identities above. If we're // here, none of them fit. // * call set_identity() to store - if (status == PEP_STATUS_OK) { + if (status == PEP_STATUS_OK) + // FIXME: Do we set if we had to copy in the address? status = set_identity(session, identity); - if (status == PEP_STATUS_OK) { - elect_pubkey(session, identity); - } - } // * Return: created identity } } @@ -649,8 +656,8 @@ DYNAMIC_API PEP_STATUS update_identity( } else { /* + * Input: address (no others) * Temporary identity information without username suplied - * Input: address (no others) */ // * Again, see if there is an own identity that uses this address. If so, we'll @@ -845,12 +852,12 @@ PEP_STATUS _myself(PEP_SESSION session, pEp_identity * identity, bool do_keygen, if (status == PEP_OUT_OF_MEMORY) return PEP_OUT_OF_MEMORY; - // Set usernames - priority is input username > stored name > "Anonymous" + // Set usernames - priority is input username > stored name > address // If there's an input username, we always patch the username with that // input. if (EMPTYSTR(identity->username)) { bool stored_uname = (stored_identity && stored_identity->username); - char* uname = (stored_uname ? stored_identity->username : "Anonymous"); + char* uname = (stored_uname ? stored_identity->username : identity->address); free(identity->username); identity->username = strdup(uname); if (identity->username == NULL) diff --git a/src/message_api.c b/src/message_api.c index 62503a7f..02630e60 100644 --- a/src/message_api.c +++ b/src/message_api.c @@ -3451,21 +3451,21 @@ DYNAMIC_API PEP_STATUS MIME_encrypt_message( if (status != PEP_STATUS_OK) GOTO(pep_error); } - - // Own identities can be retrieved here where they would otherwise - // fail because we lack all other information. This is ok and even - // desired. FIXME: IS it? - status = update_identity_recip_list(session, tmp_msg->to); - if (status != PEP_STATUS_OK) - GOTO(pep_error); - - status = update_identity_recip_list(session, tmp_msg->cc); - if (status != PEP_STATUS_OK) - GOTO(pep_error); - - status = update_identity_recip_list(session, tmp_msg->bcc); - if (status != PEP_STATUS_OK) - GOTO(pep_error); + // + // // Own identities can be retrieved here where they would otherwise + // // fail because we lack all other information. This is ok and even + // // desired. FIXME: IS it? + // status = update_identity_recip_list(session, tmp_msg->to); + // if (status != PEP_STATUS_OK) + // GOTO(pep_error); + // + // status = update_identity_recip_list(session, tmp_msg->cc); + // if (status != PEP_STATUS_OK) + // GOTO(pep_error); + // + // status = update_identity_recip_list(session, tmp_msg->bcc); + // if (status != PEP_STATUS_OK) + // GOTO(pep_error); // This isn't incoming, though... so we need to reverse the direction tmp_msg->dir = PEP_dir_outgoing; diff --git a/test/new_update_id_and_myself_test.cc b/test/new_update_id_and_myself_test.cc index 99f67dfb..697c6af4 100644 --- a/test/new_update_id_and_myself_test.cc +++ b/test/new_update_id_and_myself_test.cc @@ -334,8 +334,11 @@ int main() { somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); status = update_identity(session, somebody); - assert(status == PEP_CANNOT_FIND_IDENTITY); - cout << "PASS: update_identity() returns PEP_CANNOT_FIND_IDENTITY" << endl << endl; + assert(status == PEP_STATUS_OK); + assert(!somebody->fpr); + assert(somebody->comm_type == PEP_ct_key_not_found); + + cout << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl; free_identity(somebody);