ENGINE-289: fixed bad status carryover ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 10 Jan 2018 08:18:52 +0100
branchENGINE-289
changeset 23695c1d477fd5ad
parent 2368 9e1609eeade3
child 2370 b37530bf26fa
ENGINE-289: fixed bad status carryover
src/keymanagement.c
test/least_color_group_test.cc
     1.1 --- a/src/keymanagement.c	Tue Jan 09 13:27:56 2018 +0100
     1.2 +++ b/src/keymanagement.c	Wed Jan 10 08:18:52 2018 +0100
     1.3 @@ -469,9 +469,11 @@
     1.4          }
     1.5          //  * else (identity unavailable)
     1.6          else {
     1.7 +            status = PEP_STATUS_OK;
     1.8 +            
     1.9              //  if we only have user_id and address and identity not available
    1.10              //      * return error status (identity not found)
    1.11 -            if (!identity->username)
    1.12 +            if (!(identity->username))
    1.13                  status = PEP_CANNOT_FIND_IDENTITY;
    1.14              
    1.15              // Otherwise, if we had user_id, address, and username:
    1.16 @@ -710,11 +712,9 @@
    1.17               !own_id)))
    1.18          return ADD_TO_LOG(PEP_ILLEGAL_VALUE);
    1.19  
    1.20 -    if (!own_id) {
    1.21 -        // check to see if we have ANY identity for this address... could have
    1.22 -        // happened due to race condition
    1.23 -    }
    1.24 -    
    1.25 +    // IF WE DON'T HAVE AN OWN_ID, WE IGNORE REFERENCES TO THIS ADDRESS IN THE
    1.26 +    // DB, AS IT IS NOT AN OWN_IDENTITY AND HAS NO INFORMATION WE NEED OR WHAT TO
    1.27 +    // SET FOR MYSELF
    1.28      identity->comm_type = PEP_ct_pEp;
    1.29      identity->me = true;
    1.30      if(ignore_flags)
    1.31 @@ -728,6 +728,20 @@
    1.32          if (identity->user_id == NULL)
    1.33              return PEP_OUT_OF_MEMORY;
    1.34      }
    1.35 +    else if (own_id) {
    1.36 +        if (strcmp(identity->user_id, own_id) != 0) {
    1.37 +            if (strcmp(own_id, PEP_OWN_USERID) == 0) {
    1.38 +                // replace own_id in DB
    1.39 +                status = replace_userid(session, PEP_OWN_USERID,
    1.40 +                                        identity->user_id);
    1.41 +                if (status != PEP_STATUS_OK)
    1.42 +                    return status;
    1.43 +            }
    1.44 +            else {
    1.45 +                return PEP_CANNOT_SET_IDENTITY; // FIXME: Better error
    1.46 +            }
    1.47 +        }
    1.48 +    }
    1.49  
    1.50      if (EMPTYSTR(identity->username))
    1.51      {
    1.52 @@ -891,7 +905,7 @@
    1.53          }
    1.54      }
    1.55  
    1.56 -    if (!identity->username)
    1.57 +    if (!(identity->username))
    1.58          identity->username = strdup("");
    1.59      
    1.60      status = set_identity(session, identity);
     2.1 --- a/test/least_color_group_test.cc	Tue Jan 09 13:27:56 2018 +0100
     2.2 +++ b/test/least_color_group_test.cc	Wed Jan 10 08:18:52 2018 +0100
     2.3 @@ -48,14 +48,11 @@
     2.4                                        PEP_OWN_USERID, "Pep Color Test P (recip)");
     2.5      me1->me = true;
     2.6      PEP_STATUS status = update_identity(session, me1);
     2.7 -    trust_personal_key(session, me1);
     2.8 -    status = update_identity(session, me1);
     2.9      
    2.10      pEp_identity * sender1 = new_identity("pep.color.test.V@kgrothoff.org",
    2.11                                            NULL, "TOFU_pep.color.test.V@kgrothoff.org",
    2.12                                            "Pep Color Test V (sender)");
    2.13      
    2.14 -    sender1->me = false;
    2.15      status = update_identity(session, sender1);
    2.16      trust_personal_key(session, sender1);
    2.17      status = update_identity(session, sender1);