Fixed ENGINE-364 and some test bugs. Users now much be CERTAIN to call update_identity if they need the comm_type afte trust_personal_key (this is in accord with the API)
authorKrista Bennett <krista@pep-project.org>
Sun, 11 Feb 2018 17:02:19 +0100
changeset 249456c577c84996
parent 2493 a4fd5af7fde1
child 2495 ce2a95430d2d
Fixed ENGINE-364 and some test bugs. Users now much be CERTAIN to call update_identity if they need the comm_type afte trust_personal_key (this is in accord with the API)
src/keymanagement.c
src/keymanagement.h
test/new_update_id_and_myself_test.cc
     1.1 --- a/src/keymanagement.c	Fri Feb 09 16:32:47 2018 +0100
     1.2 +++ b/src/keymanagement.c	Sun Feb 11 17:02:19 2018 +0100
     1.3 @@ -856,7 +856,7 @@
     1.4      // If there's an input username, we always patch the username with that
     1.5      // input.
     1.6      if (EMPTYSTR(identity->username)) {
     1.7 -        bool stored_uname = (stored_identity && stored_identity->username);
     1.8 +        bool stored_uname = (stored_identity && !EMPTYSTR(stored_identity->username));
     1.9          char* uname = (stored_uname ? stored_identity->username : identity->address);
    1.10          free(identity->username);
    1.11          identity->username = strdup(uname);
    1.12 @@ -1241,19 +1241,28 @@
    1.13      status = set_pgp_keypair(session, ident->fpr);
    1.14      if (status != PEP_STATUS_OK)
    1.15          return status;
    1.16 -        
    1.17 -    // Save the input fpr
    1.18 -    char* cached_fpr = strdup(ident->fpr);
    1.19 -    ident->fpr = NULL;
    1.20  
    1.21      bool me = is_me(session, ident);
    1.22  
    1.23 -    if (me)
    1.24 -        return myself(session, ident); // FIXME: Not the right thing if we 
    1.25 -                                       // don't always replace user default!!!
    1.26 +    pEp_identity* ident_copy = identity_dup(ident);
    1.27 +    char* cached_fpr = NULL;
    1.28 +
    1.29 +    // for setting up a temp trusted identity for the input fpr
    1.30 +    pEp_identity* tmp_id = NULL;
    1.31 +
    1.32 +    if (me) {
    1.33 +        status = myself(session, ident_copy); 
    1.34 +        goto pep_free;
    1.35 +    }
    1.36 +    
    1.37 +    // For later, in case we need to check the user default key
    1.38 +    pEp_identity* tmp_user_ident = NULL;
    1.39 +    
    1.40 +    // Save the input fpr
    1.41 +    cached_fpr = strdup(ident->fpr);
    1.42  
    1.43      // First, set up a temp trusted identity for the input fpr without a comm type;
    1.44 -    pEp_identity* tmp_id = new_identity(ident->address, cached_fpr, ident->user_id, NULL);
    1.45 +    tmp_id = new_identity(ident->address, ident->fpr, ident->user_id, NULL);
    1.46      status = validate_fpr(session, tmp_id);
    1.47          
    1.48      if (status == PEP_STATUS_OK) {
    1.49 @@ -1262,8 +1271,8 @@
    1.50          tmp_id->comm_type = _MAX(tmp_id->comm_type, input_default_ct) | PEP_ct_confirmed;
    1.51                                         
    1.52          // Get the default identity without setting the fpr
    1.53 -        status = update_identity(session, ident);
    1.54 -        ident_default_fpr = strdup(ident->fpr);
    1.55 +        status = update_identity(session, ident_copy);
    1.56 +        ident_default_fpr = strdup(ident_copy->fpr);
    1.57  
    1.58          if (status == PEP_STATUS_OK) {
    1.59              bool trusted_default = false;
    1.60 @@ -1283,10 +1292,10 @@
    1.61                      input_default_ct = tmp_id->comm_type;                    
    1.62                  }
    1.63                  else {
    1.64 -                    free(ident->fpr);
    1.65 -                    ident->fpr = strdup(cached_fpr);
    1.66 -                    ident->comm_type = tmp_id->comm_type;
    1.67 -                    status = set_identity(session, ident); // replace identity default            
    1.68 +                    free(ident_copy->fpr);
    1.69 +                    ident_copy->fpr = strdup(cached_fpr);
    1.70 +                    ident_copy->comm_type = tmp_id->comm_type;
    1.71 +                    status = set_identity(session, ident_copy); // replace identity default            
    1.72                  }
    1.73              }
    1.74              else { // we're setting this on the default fpr
    1.75 @@ -1302,10 +1311,10 @@
    1.76                  status = get_main_user_fpr(session, ident->user_id, &user_default);
    1.77              
    1.78                  if (status == PEP_STATUS_OK && user_default) {
    1.79 -                    pEp_identity* tmp_user_ident = new_identity(ident->address, 
    1.80 -                                                                user_default, 
    1.81 -                                                                ident->user_id, 
    1.82 -                                                                NULL);
    1.83 +                    tmp_user_ident = new_identity(ident->address, 
    1.84 +                                                  user_default, 
    1.85 +                                                  ident->user_id, 
    1.86 +                                                  NULL);
    1.87                      if (!tmp_user_ident)
    1.88                          status = PEP_OUT_OF_MEMORY;
    1.89                      else {
    1.90 @@ -1322,11 +1331,14 @@
    1.91                  }
    1.92              }
    1.93          }
    1.94 -        free(ident_default_fpr);
    1.95 -        free(cached_fpr);
    1.96 -        free_identity(tmp_id);
    1.97      }    
    1.98  
    1.99 +pep_free:
   1.100 +    free(ident_default_fpr);
   1.101 +    free(cached_fpr);
   1.102 +    free_identity(tmp_id);
   1.103 +    free_identity(ident_copy);
   1.104 +    free_identity(tmp_user_ident);
   1.105      return status;
   1.106  }
   1.107  
     2.1 --- a/src/keymanagement.h	Fri Feb 09 16:32:47 2018 +0100
     2.2 +++ b/src/keymanagement.h	Sun Feb 11 17:02:19 2018 +0100
     2.3 @@ -231,7 +231,7 @@
     2.4  //
     2.5  //  caveat:
     2.6  //      the fields user_id, address and fpr must be supplied
     2.7 -//      for non-own users, this will 1) set the trust bit on its comm type in the DN,
     2.8 +//      for non-own users, this will 1) set the trust bit on its comm type in the DB,
     2.9  //      2) set this key as the identity default if the current identity default
    2.10  //      is not trusted, and 3) set this key as the user default if the current
    2.11  //      user default is not trusted.
     3.1 --- a/test/new_update_id_and_myself_test.cc	Fri Feb 09 16:32:47 2018 +0100
     3.2 +++ b/test/new_update_id_and_myself_test.cc	Sun Feb 11 17:02:19 2018 +0100
     3.3 @@ -530,13 +530,17 @@
     3.4      free(revokemaster_3000->fpr);
     3.5      revokemaster_3000->fpr = strdup(revoke_fpr_arr[2]);
     3.6      status = trust_personal_key(session, revokemaster_3000);
     3.7 -    assert(status == PEP_STATUS_OK); 
     3.8 +    assert(status == PEP_STATUS_OK);
     3.9 +    status = get_trust(session, revokemaster_3000);
    3.10 +    assert(status == PEP_STATUS_OK);
    3.11      assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
    3.12  
    3.13      free(revokemaster_3000->fpr);
    3.14      revokemaster_3000->fpr = strdup(revoke_fpr_arr[0]);
    3.15      status = trust_personal_key(session, revokemaster_3000);
    3.16      assert(status == PEP_STATUS_OK);
    3.17 +    status = get_trust(session, revokemaster_3000);
    3.18 +    assert(status == PEP_STATUS_OK);
    3.19      assert(revokemaster_3000->comm_type & PEP_ct_confirmed);
    3.20      
    3.21      status = update_identity(session, revokemaster_3000);