ENGINE-379 and probably other problems: was calling set_identity from within set_as_pep_user, which was called by get_trust, which is called from set_identity. So... yeah. Bad.
authorKrista Bennett <krista@pep-project.org>
Wed, 14 Feb 2018 16:02:08 +0100
changeset 250499b930afc2a0
parent 2503 6f78d64d39ca
child 2505 1102a11afe18
ENGINE-379 and probably other problems: was calling set_identity from within set_as_pep_user, which was called by get_trust, which is called from set_identity. So... yeah. Bad.
src/keymanagement.c
src/pEpEngine.c
     1.1 --- a/src/keymanagement.c	Tue Feb 13 16:08:48 2018 +0100
     1.2 +++ b/src/keymanagement.c	Wed Feb 14 16:02:08 2018 +0100
     1.3 @@ -975,6 +975,8 @@
     1.4      }
     1.5      
     1.6      status = set_identity(session, identity);
     1.7 +    if (status == PEP_STATUS_OK)
     1.8 +        status = set_as_pep_user(session, identity);
     1.9  
    1.10  pep_free:    
    1.11      free(default_own_id);
    1.12 @@ -1144,7 +1146,12 @@
    1.13      else {
    1.14          status = delete_mistrusted_key(session, cached_ident->fpr);
    1.15          if (status == PEP_STATUS_OK) {
    1.16 -            status = set_identity(session, cached_ident);            
    1.17 +            status = set_identity(session, cached_ident);
    1.18 +            // THIS SHOULDN'T BE NECESSARY - PREVIOUS VALUE WAS IN THE DB
    1.19 +            // if (status == PEP_STATUS_OK) {
    1.20 +            //     if ((cached_ident->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
    1.21 +            //         status = set_as_pep_user(session, cached_ident);
    1.22 +            // }            
    1.23              free_identity(session->cached_mistrusted);
    1.24          }
    1.25      }
    1.26 @@ -1326,7 +1333,11 @@
    1.27                      free(ident_copy->fpr);
    1.28                      ident_copy->fpr = strdup(cached_fpr);
    1.29                      ident_copy->comm_type = tmp_id->comm_type;
    1.30 -                    status = set_identity(session, ident_copy); // replace identity default            
    1.31 +                    status = set_identity(session, ident_copy); // replace identity default
    1.32 +                    if (status == PEP_STATUS_OK) {
    1.33 +                        if ((ident_copy->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
    1.34 +                            status = set_as_pep_user(session, ident_copy);
    1.35 +                    }            
    1.36                  }
    1.37              }
    1.38              else { // we're setting this on the default fpr
     2.1 --- a/src/pEpEngine.c	Tue Feb 13 16:08:48 2018 +0100
     2.2 +++ b/src/pEpEngine.c	Wed Feb 14 16:02:08 2018 +0100
     2.3 @@ -1463,7 +1463,7 @@
     2.4          const char *comment
     2.5      )
     2.6  {
     2.7 -    PEP_STATUS status = PEP_STATUS_OK;
     2.8 +//    PEP_STATUS status = PEP_STATUS_OK;
     2.9      int result;
    2.10  
    2.11      assert(session);
    2.12 @@ -2241,12 +2241,20 @@
    2.13  
    2.14  PEP_STATUS _set_trust_internal(PEP_SESSION session, pEp_identity* identity,
    2.15                                 bool guard_transaction) {
    2.16 -    PEP_STATUS status = set_or_update_with_identity(session, identity,
    2.17 -                                                    _set_or_update_trust,
    2.18 -                                                    exists_trust_entry,
    2.19 -                                                    session->update_trust,
    2.20 -                                                    session->set_trust,
    2.21 -                                                    guard_transaction);
    2.22 +    return set_or_update_with_identity(session, identity,
    2.23 +                                       _set_or_update_trust,
    2.24 +                                        exists_trust_entry,
    2.25 +                                        session->update_trust,
    2.26 +                                        session->set_trust,
    2.27 +                                        guard_transaction);
    2.28 +}
    2.29 +
    2.30 +// This is the TOP-LEVEL function. If you're calling from set_identity,
    2.31 +// you can't use this one.
    2.32 +PEP_STATUS set_trust(PEP_SESSION session, pEp_identity* identity) {
    2.33 +    PEP_STATUS status = PEP_STATUS_OK;
    2.34 +    
    2.35 +    status = _set_trust_internal(session, identity, true);
    2.36      if (status == PEP_STATUS_OK) {
    2.37          if ((identity->comm_type | PEP_ct_confirmed) == PEP_ct_pEp)
    2.38              status = set_as_pep_user(session, identity);
    2.39 @@ -2254,10 +2262,6 @@
    2.40      return status;
    2.41  }
    2.42  
    2.43 -PEP_STATUS set_trust(PEP_SESSION session, pEp_identity* identity) {
    2.44 -    return _set_trust_internal(session, identity, true);
    2.45 -}
    2.46 -
    2.47  PEP_STATUS set_person(PEP_SESSION session, pEp_identity* identity,
    2.48                        bool guard_transaction) {
    2.49      return set_or_update_with_identity(session, identity,
    2.50 @@ -2278,6 +2282,7 @@
    2.51                                         guard_transaction);
    2.52  }
    2.53  
    2.54 +// This will NOT call set_as_pep_user; you have to do that separately.
    2.55  DYNAMIC_API PEP_STATUS set_identity(
    2.56          PEP_SESSION session, const pEp_identity *identity
    2.57      )
    2.58 @@ -2368,7 +2373,7 @@
    2.59      return status;
    2.60  }
    2.61  
    2.62 -// This ONLY sets the user flag, and creates a shell identity if necessary.
    2.63 +// This ONLY sets the user flag. Must be called outside of a transaction.
    2.64  PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user) {
    2.65  
    2.66      assert(session);
    2.67 @@ -2387,17 +2392,8 @@
    2.68      if (status != PEP_STATUS_OK)
    2.69          return status;
    2.70          
    2.71 -    if (!person_exists) {
    2.72 -        if (!user->address)
    2.73 -            return PEP_ILLEGAL_VALUE;
    2.74 -            
    2.75 -        // create shell identity
    2.76 -        pEp_identity* tmp_id = new_identity(user->address, NULL, user->user_id, user->username);
    2.77 -        status = set_identity(session, tmp_id); // this creates the person
    2.78 -        free_identity(tmp_id);
    2.79 -        if (status != PEP_STATUS_OK)
    2.80 -            return status;
    2.81 -    }
    2.82 +    if (!person_exists)
    2.83 +        status = set_person(session, user, true);
    2.84          
    2.85      // Ok, let's set it.
    2.86      sqlite3_reset(session->set_as_pep_user);