ENGINE-463: incoming TOFU and stored real defaults to stored real; may have removed problem with TOFU_ TOFU_ clash in update_identity
1.1 --- a/src/keymanagement.c Thu Oct 04 07:10:08 2018 +0200
1.2 +++ b/src/keymanagement.c Thu Oct 04 12:05:21 2018 +0200
1.3 @@ -532,40 +532,51 @@
1.4
1.5 if (id_list) {
1.6 identity_list* id_curr = id_list;
1.7 + bool input_is_TOFU = strstr(identity->user_id, "TOFU_") == identity->user_id;
1.8 while (id_curr) {
1.9 pEp_identity* this_id = id_curr->ident;
1.10 if (this_id) {
1.11 char* this_uid = this_id->user_id;
1.12 - if (this_uid && (strstr(this_uid, "TOFU_") == this_uid)) {
1.13 - // FIXME: should we also be fixing pEp_own_userId in this
1.14 - // function here?
1.15 -
1.16 - // if usernames match, we replace the userid. Or if the temp username
1.17 - // is anonymous.
1.18 - // FIXME: do we need to create an address match function which
1.19 - // matches the whole dot-and-case rigamarole from
1.20 - if (EMPTYSTR(this_id->username) ||
1.21 - strcasecmp(this_id->username, this_id->address) == 0 ||
1.22 - (identity->username &&
1.23 - strcasecmp(identity->username,
1.24 - this_id->username) == 0)) {
1.25 + bool curr_is_TOFU = strstr(this_uid, "TOFU_") == this_uid;
1.26 + if (this_uid) {
1.27 + if (curr_is_TOFU && !input_is_TOFU) {
1.28 + // FIXME: should we also be fixing pEp_own_userId in this
1.29 + // function here?
1.30
1.31 - // Ok, we have a temp ID. We have to replace this
1.32 - // with the real ID.
1.33 - status = replace_userid(session,
1.34 - this_uid,
1.35 - identity->user_id);
1.36 - if (status != PEP_STATUS_OK) {
1.37 - free_identity_list(id_list);
1.38 - free(default_own_id);
1.39 - return status;
1.40 + // if usernames match, we replace the userid. Or if the temp username
1.41 + // is anonymous.
1.42 + // FIXME: do we need to create an address match function which
1.43 + // matches the whole dot-and-case rigamarole from
1.44 + if (EMPTYSTR(this_id->username) ||
1.45 + strcasecmp(this_id->username, this_id->address) == 0 ||
1.46 + (identity->username &&
1.47 + strcasecmp(identity->username,
1.48 + this_id->username) == 0)) {
1.49 +
1.50 + // Ok, we have a temp ID. We have to replace this
1.51 + // with the real ID.
1.52 + status = replace_userid(session,
1.53 + this_uid,
1.54 + identity->user_id);
1.55 + if (status != PEP_STATUS_OK) {
1.56 + free_identity_list(id_list);
1.57 + free(default_own_id);
1.58 + return status;
1.59 + }
1.60 +
1.61 + free(this_uid);
1.62 + this_uid = NULL;
1.63 +
1.64 + // Reflect the change we just made to the DB
1.65 + this_id->user_id = strdup(identity->user_id);
1.66 + stored_ident = this_id;
1.67 + // FIXME: free list.
1.68 + break;
1.69 }
1.70 -
1.71 - free(this_uid);
1.72 - this_uid = NULL;
1.73 -
1.74 - // Reflect the change we just made to the DB
1.75 - this_id->user_id = strdup(identity->user_id);
1.76 + }
1.77 + else if (input_is_TOFU && !curr_is_TOFU) {
1.78 + // Replace ruthlessly - this is NOT supposed to happen.
1.79 + // BAD APP BEHAVIOUR.
1.80 stored_ident = this_id;
1.81 // FIXME: free list.
1.82 break;