ENGINE-527: update_identity will now also not write when it has an own address, but no user_id
authorKrista 'DarthMama' Bennett <krista@pep.foundation>
Wed, 20 Mar 2019 12:21:38 +0100
changeset 33494320b0f44436
parent 3346 278702033186
child 3350 1c117fa0df8e
ENGINE-527: update_identity will now also not write when it has an own address, but no user_id
src/keymanagement.c
src/pEpEngine.c
src/pEpEngine.h
     1.1 --- a/src/keymanagement.c	Tue Mar 19 18:19:59 2019 +0100
     1.2 +++ b/src/keymanagement.c	Wed Mar 20 12:21:38 2019 +0100
     1.3 @@ -540,9 +540,44 @@
     1.4      char* default_own_id = NULL;
     1.5      status = get_default_own_userid(session, &default_own_id);    
     1.6  
     1.7 -    // Is this me, temporary or not? If so, BAIL.
     1.8 -    if (identity->me || 
     1.9 -       (default_own_id && identity->user_id && (strcmp(default_own_id, identity->user_id) == 0))) 
    1.10 +    bool is_own_user = identity->me;
    1.11 +
    1.12 +    // Is this me, temporary or not? If so, BAIL.    
    1.13 +    if (!is_own_user) {
    1.14 +        if (default_own_id) {
    1.15 +            if (!EMPTYSTR(identity->user_id)) {
    1.16 +                if (strcmp(default_own_id, identity->user_id) == 0) {
    1.17 +                    is_own_user = true;
    1.18 +                }
    1.19 +                else {
    1.20 +                    char* alias = NULL;
    1.21 +                    if (get_userid_alias_default(session, identity->user_id, &alias) == PEP_STATUS_OK) {
    1.22 +                        if (alias && strcmp(default_own_id, alias) == 0)
    1.23 +                            is_own_user = true;
    1.24 +                        free(alias);    
    1.25 +                    }
    1.26 +                }
    1.27 +            }
    1.28 +            else {
    1.29 +                // Check if own address. For now, this is a special case;
    1.30 +                // we try to require apps to send in user_ids, but must prevent
    1.31 +                // writes to an own identity from within THIS function
    1.32 +                // NOTE: These semantics MAY CHANGE.
    1.33 +                bool _own_addr = false;
    1.34 +                is_own_address(session, identity->address, &_own_addr);
    1.35 +                
    1.36 +                // N.B. KB: I would prefer consistent semantics here - that is to say,
    1.37 +                // we also set is_own_user here and force PEP_ILLEGAL_VALUE                
    1.38 +                if (_own_addr) {
    1.39 +                    free(identity->user_id);
    1.40 +                    identity->user_id = strdup(default_own_id);
    1.41 +                    return _myself(session, identity, false, false, true);
    1.42 +                }    
    1.43 +            }
    1.44 +        }
    1.45 +        // Otherwise, we don't even HAVE an own user yet, so we're ok.
    1.46 +    }    
    1.47 +    if (is_own_user)
    1.48      {
    1.49          free(default_own_id);
    1.50          return PEP_ILLEGAL_VALUE;
     2.1 --- a/src/pEpEngine.c	Tue Mar 19 18:19:59 2019 +0100
     2.2 +++ b/src/pEpEngine.c	Wed Mar 20 12:21:38 2019 +0100
     2.3 @@ -2740,20 +2740,17 @@
     2.4      return PEP_STATUS_OK;
     2.5  }
     2.6  
     2.7 -DYNAMIC_API PEP_STATUS is_own_address(PEP_SESSION session, pEp_identity *identity, bool* is_own_addr)
     2.8 +PEP_STATUS is_own_address(PEP_SESSION session, const char* address, bool* is_own_addr)
     2.9  {
    2.10      assert(session);
    2.11      assert(is_own_addr);
    2.12 -    assert(identity);
    2.13 -    assert(!EMPTYSTR(identity->user_id));
    2.14 -
    2.15 -    if (!session || !is_own_addr || !identity || EMPTYSTR(identity->address))
    2.16 +    assert(!EMPTYSTR(address));
    2.17 +
    2.18 +    if (!session || !is_own_addr || EMPTYSTR(address))
    2.19          return PEP_ILLEGAL_VALUE;
    2.20      
    2.21      *is_own_addr = false;
    2.22 -            
    2.23 -    const char* address = identity->address;
    2.24 -    
    2.25 +                
    2.26      if (!session || EMPTYSTR(address))
    2.27          return PEP_ILLEGAL_VALUE;
    2.28          
     3.1 --- a/src/pEpEngine.h	Tue Mar 19 18:19:59 2019 +0100
     3.2 +++ b/src/pEpEngine.h	Wed Mar 20 12:21:38 2019 +0100
     3.3 @@ -1261,6 +1261,10 @@
     3.4          identity_list** id_list
     3.5      );
     3.6          
     3.7 +PEP_STATUS is_own_address(PEP_SESSION session, 
     3.8 +                          const char* address, 
     3.9 +                          bool* is_own_addr);
    3.10 +
    3.11  PEP_STATUS replace_userid(PEP_SESSION session, const char* old_uid,
    3.12                                const char* new_uid);
    3.13