set_pep_user also updates all of its trust values in the DB; validate_fpr also upgrades to pEp it what it returns when there's a pep user enigmail_tests_pre_revision_2535
authorKrista Bennett <krista@pep-project.org>
Sat, 24 Feb 2018 21:44:46 +0100
branchenigmail_tests_pre_revision_2535
changeset 2542b7f6df848795
parent 2538 be573c5f4782
set_pep_user also updates all of its trust values in the DB; validate_fpr also upgrades to pEp it what it returns when there's a pep user
src/keymanagement.c
src/pEpEngine.c
src/pEp_internal.h
     1.1 --- a/src/keymanagement.c	Sat Feb 24 19:12:11 2018 +0100
     1.2 +++ b/src/keymanagement.c	Sat Feb 24 21:44:46 2018 +0100
     1.3 @@ -136,6 +136,22 @@
     1.4          ident->comm_type = ct;
     1.5      }
     1.6      
     1.7 +    bool pep_user = false;
     1.8 +    
     1.9 +    is_pep_user(session, ident, &pep_user);
    1.10 +
    1.11 +    if (pep_user) {
    1.12 +        switch (ct) {
    1.13 +            case PEP_ct_OpenPGP:
    1.14 +            case PEP_ct_OpenPGP_unconfirmed:
    1.15 +                ct += 0x47; // difference between PEP and OpenPGP values;
    1.16 +                ident->comm_type = ct;
    1.17 +                break;
    1.18 +            default:
    1.19 +                break;
    1.20 +        }
    1.21 +    }
    1.22 +    
    1.23      bool revoked, expired;
    1.24      bool blacklisted = false;
    1.25      
     2.1 --- a/src/pEpEngine.c	Sat Feb 24 19:12:11 2018 +0100
     2.2 +++ b/src/pEpEngine.c	Sat Feb 24 21:44:46 2018 +0100
     2.3 @@ -284,6 +284,14 @@
     2.4      "update trust set comm_type = ?3 " 
     2.5      "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
     2.6  
     2.7 +static const char *sql_update_trust_to_pep =
     2.8 +    "update trust set comm_type = comm_type + 71 "
     2.9 +    "   where (user_id = ?1 "
    2.10 +    "          and (case when (comm_type = 56) then (1) "
    2.11 +    "                    when (comm_type = 184) then (1) "
    2.12 +    "                    else 0"
    2.13 +    "               end) = 1); ";
    2.14 +
    2.15  static const char* sql_exists_trust_entry = 
    2.16      "select count(*) from trust "
    2.17      "   where user_id = ?1 and pgp_keypair_fpr = upper(replace(?2,' ',''));";
    2.18 @@ -1163,6 +1171,10 @@
    2.19              (int)strlen(sql_update_trust), &_session->update_trust, NULL);
    2.20      assert(int_result == SQLITE_OK);
    2.21  
    2.22 +    int_result = sqlite3_prepare_v2(_session->db, sql_update_trust_to_pep,
    2.23 +            (int)strlen(sql_update_trust_to_pep), &_session->update_trust_to_pep, NULL);
    2.24 +    assert(int_result == SQLITE_OK);
    2.25 +
    2.26      int_result = sqlite3_prepare_v2(_session->db, sql_exists_trust_entry,
    2.27                   (int)strlen(sql_exists_trust_entry), &_session->exists_trust_entry, NULL);
    2.28      assert(int_result == SQLITE_OK);
    2.29 @@ -1401,7 +1413,9 @@
    2.30              if (session->set_trust)
    2.31                  sqlite3_finalize(session->set_trust);
    2.32              if (session->update_trust)
    2.33 -                sqlite3_finalize(session->update_trust);                
    2.34 +                sqlite3_finalize(session->update_trust);
    2.35 +            if (session->update_trust_to_pep)
    2.36 +                sqlite3_finalize(session->update_trust_to_pep);                                                
    2.37              if (session->update_trust_for_fpr)
    2.38                  sqlite3_finalize(session->update_trust_for_fpr);
    2.39              if (session->get_trust)
    2.40 @@ -2437,6 +2451,23 @@
    2.41      return status;
    2.42  }
    2.43  
    2.44 +PEP_STATUS update_pep_user_trust_vals(PEP_SESSION session,
    2.45 +                                      pEp_identity* user) {
    2.46 +    if (!user->user_id)
    2.47 +        return PEP_ILLEGAL_VALUE;
    2.48 +    
    2.49 +    sqlite3_reset(session->update_trust_to_pep);
    2.50 +    sqlite3_bind_text(session->update_trust_to_pep, 1, user->user_id, -1,
    2.51 +            SQLITE_STATIC);
    2.52 +    int result = sqlite3_step(session->update_trust_to_pep);
    2.53 +    sqlite3_reset(session->update_trust_to_pep);
    2.54 +    if (result != SQLITE_DONE)
    2.55 +        return PEP_CANNOT_SET_TRUST;
    2.56 +
    2.57 +    return PEP_STATUS_OK;
    2.58 +}
    2.59 +
    2.60 +
    2.61  // This ONLY sets the user flag. Must be called outside of a transaction.
    2.62  PEP_STATUS set_as_pep_user(PEP_SESSION session, pEp_identity* user) {
    2.63  
    2.64 @@ -2468,8 +2499,10 @@
    2.65      
    2.66      if (result != SQLITE_DONE)
    2.67          return PEP_CANNOT_SET_PERSON;
    2.68 +
    2.69 +    status = update_pep_user_trust_vals(session, user);
    2.70          
    2.71 -    return PEP_STATUS_OK;    
    2.72 +    return status;
    2.73  }
    2.74  
    2.75  PEP_STATUS exists_person(PEP_SESSION session, pEp_identity* identity,
     3.1 --- a/src/pEp_internal.h	Sat Feb 24 19:12:11 2018 +0100
     3.2 +++ b/src/pEp_internal.h	Sat Feb 24 21:44:46 2018 +0100
     3.3 @@ -144,7 +144,8 @@
     3.4      sqlite3_stmt *set_identity_flags;
     3.5      sqlite3_stmt *unset_identity_flags;
     3.6      sqlite3_stmt *set_trust;
     3.7 -    sqlite3_stmt *update_trust;    
     3.8 +    sqlite3_stmt *update_trust;
     3.9 +    sqlite3_stmt *update_trust_to_pep;    
    3.10      sqlite3_stmt *exists_trust_entry;
    3.11      sqlite3_stmt *update_trust_for_fpr;
    3.12      sqlite3_stmt *get_trust;