ENGINE-360: I *think* this should take care of the no-username problem.
authorKrista Bennett <krista@pep-project.org>
Fri, 09 Feb 2018 16:32:47 +0100
changeset 2493a4fd5af7fde1
parent 2492 323e040d1a17
child 2494 56c577c84996
ENGINE-360: I *think* this should take care of the no-username problem.
src/keymanagement.c
src/message_api.c
test/new_update_id_and_myself_test.cc
     1.1 --- a/src/keymanagement.c	Fri Feb 09 10:30:50 2018 +0100
     1.2 +++ b/src/keymanagement.c	Fri Feb 09 16:32:47 2018 +0100
     1.3 @@ -394,15 +394,18 @@
     1.4      //  a DB username, we replace)
     1.5      if (!EMPTYSTR(stored_ident->username)) {
     1.6          if (!EMPTYSTR(return_id->username) && 
     1.7 -            (strcasecmp(return_id->username, "anonymous") == 0)) {
     1.8 +            (strcasecmp(return_id->username, return_id->address) == 0)) {
     1.9              free(return_id->username);
    1.10 -            return_id->username = NULL;
    1.11          }
    1.12          if (EMPTYSTR(return_id->username)) {
    1.13              free(return_id->username);
    1.14              return_id->username = strdup(stored_ident->username);
    1.15          }
    1.16      }
    1.17 +    else {
    1.18 +        if (EMPTYSTR(return_id->username))
    1.19 +            return_id->username = strdup(return_id->address);
    1.20 +    }
    1.21      
    1.22      return_id->me = stored_ident->me;
    1.23      
    1.24 @@ -494,8 +497,10 @@
    1.25                              
    1.26                              // if usernames match, we replace the userid. Or if the temp username
    1.27                              // is anonymous.
    1.28 +                            // FIXME: do we need to create an address match function which
    1.29 +                            // matches the whole dot-and-case rigamarole from 
    1.30                              if (EMPTYSTR(this_id->username) ||
    1.31 -                                strcasecmp(this_id->username, "anonymous") == 0 ||
    1.32 +                                strcasecmp(this_id->username, this_id->address) == 0 ||
    1.33                                  (identity->username && 
    1.34                                   strcasecmp(identity->username, 
    1.35                                              this_id->username) == 0)) {
    1.36 @@ -541,29 +546,31 @@
    1.37          //  * else (identity unavailable)
    1.38          else {
    1.39              status = PEP_STATUS_OK;
    1.40 -            
    1.41 +
    1.42 +            // FIXME: We may need to roll this back.
    1.43 +            // FIXME: change docs if we don't
    1.44              //  if we only have user_id and address and identity not available
    1.45              //      * return error status (identity not found)
    1.46 -            if (EMPTYSTR(identity->username))
    1.47 -                status = PEP_CANNOT_FIND_IDENTITY;
    1.48 +            if (EMPTYSTR(identity->username)) {
    1.49 +                free(identity->username);
    1.50 +                identity->username = strdup(identity->address);
    1.51 +            }
    1.52              
    1.53              // Otherwise, if we had user_id, address, and username:
    1.54              //    * create identity with user_id, address, username
    1.55              //      (this is the input id without the fpr + comm type!)
    1.56 -            free(identity->fpr);
    1.57 -            identity->fpr = NULL;
    1.58 -            identity->comm_type = PEP_ct_unknown;
    1.59 -            
    1.60 +
    1.61 +            if (status == PEP_STATUS_OK) {
    1.62 +                elect_pubkey(session, identity);
    1.63 +            }
    1.64 +                        
    1.65              //    * We've already checked and retrieved
    1.66              //      any applicable temporary identities above. If we're 
    1.67              //      here, none of them fit.
    1.68              //    * call set_identity() to store
    1.69 -            if (status == PEP_STATUS_OK) {
    1.70 +            if (status == PEP_STATUS_OK)
    1.71 +                // FIXME: Do we set if we had to copy in the address?
    1.72                  status = set_identity(session, identity);
    1.73 -                if (status == PEP_STATUS_OK) {
    1.74 -                    elect_pubkey(session, identity);
    1.75 -                }
    1.76 -            }
    1.77              //  * Return: created identity
    1.78          }        
    1.79      }
    1.80 @@ -649,8 +656,8 @@
    1.81      }
    1.82      else {
    1.83          /*
    1.84 +        * Input: address (no others)
    1.85           * Temporary identity information without username suplied
    1.86 -            * Input: address (no others)
    1.87           */
    1.88           
    1.89          //  * Again, see if there is an own identity that uses this address. If so, we'll
    1.90 @@ -845,12 +852,12 @@
    1.91      if (status == PEP_OUT_OF_MEMORY)
    1.92          return PEP_OUT_OF_MEMORY;
    1.93  
    1.94 -    // Set usernames - priority is input username > stored name > "Anonymous"
    1.95 +    // Set usernames - priority is input username > stored name > address
    1.96      // If there's an input username, we always patch the username with that
    1.97      // input.
    1.98      if (EMPTYSTR(identity->username)) {
    1.99          bool stored_uname = (stored_identity && stored_identity->username);
   1.100 -        char* uname = (stored_uname ? stored_identity->username : "Anonymous");
   1.101 +        char* uname = (stored_uname ? stored_identity->username : identity->address);
   1.102          free(identity->username);
   1.103          identity->username = strdup(uname);
   1.104          if (identity->username == NULL)
     2.1 --- a/src/message_api.c	Fri Feb 09 10:30:50 2018 +0100
     2.2 +++ b/src/message_api.c	Fri Feb 09 16:32:47 2018 +0100
     2.3 @@ -3451,21 +3451,21 @@
     2.4          if (status != PEP_STATUS_OK)
     2.5              GOTO(pep_error);
     2.6      }
     2.7 -
     2.8 -    // Own identities can be retrieved here where they would otherwise
     2.9 -    // fail because we lack all other information. This is ok and even
    2.10 -    // desired. FIXME: IS it?
    2.11 -    status = update_identity_recip_list(session, tmp_msg->to);
    2.12 -    if (status != PEP_STATUS_OK)
    2.13 -        GOTO(pep_error);
    2.14 -
    2.15 -    status = update_identity_recip_list(session, tmp_msg->cc);
    2.16 -    if (status != PEP_STATUS_OK)
    2.17 -        GOTO(pep_error);
    2.18 -
    2.19 -    status = update_identity_recip_list(session, tmp_msg->bcc);
    2.20 -    if (status != PEP_STATUS_OK)
    2.21 -        GOTO(pep_error);
    2.22 +    // 
    2.23 +    // // Own identities can be retrieved here where they would otherwise
    2.24 +    // // fail because we lack all other information. This is ok and even
    2.25 +    // // desired. FIXME: IS it?
    2.26 +    // status = update_identity_recip_list(session, tmp_msg->to);
    2.27 +    // if (status != PEP_STATUS_OK)
    2.28 +    //     GOTO(pep_error);
    2.29 +    // 
    2.30 +    // status = update_identity_recip_list(session, tmp_msg->cc);
    2.31 +    // if (status != PEP_STATUS_OK)
    2.32 +    //     GOTO(pep_error);
    2.33 +    // 
    2.34 +    // status = update_identity_recip_list(session, tmp_msg->bcc);
    2.35 +    // if (status != PEP_STATUS_OK)
    2.36 +    //     GOTO(pep_error);
    2.37      
    2.38      // This isn't incoming, though... so we need to reverse the direction
    2.39      tmp_msg->dir = PEP_dir_outgoing;
     3.1 --- a/test/new_update_id_and_myself_test.cc	Fri Feb 09 10:30:50 2018 +0100
     3.2 +++ b/test/new_update_id_and_myself_test.cc	Fri Feb 09 16:32:47 2018 +0100
     3.3 @@ -334,8 +334,11 @@
     3.4  
     3.5      somebody = new_identity("nope@nope.nope", NULL, "some_user_id", NULL); 
     3.6      status = update_identity(session, somebody);
     3.7 -    assert(status == PEP_CANNOT_FIND_IDENTITY);
     3.8 -    cout << "PASS: update_identity() returns PEP_CANNOT_FIND_IDENTITY" << endl << endl;
     3.9 +    assert(status == PEP_STATUS_OK);
    3.10 +    assert(!somebody->fpr);
    3.11 +    assert(somebody->comm_type == PEP_ct_key_not_found);
    3.12 +    
    3.13 +    cout << "PASS: update_identity() returns identity with no key and unknown comm type" << endl << endl;
    3.14  
    3.15      free_identity(somebody);
    3.16