src/sync_impl.c
changeset 2461 85c8e5aad3bc
parent 2271 25bfd109320c
child 2462 48b526a0daac
     1.1 --- a/src/sync_impl.c	Mon Jan 15 12:26:14 2018 +0100
     1.2 +++ b/src/sync_impl.c	Mon Jan 29 12:15:51 2018 +0100
     1.3 @@ -71,6 +71,7 @@
     1.4      assert(session && sync_msg);
     1.5      if (!(session && sync_msg))
     1.6          return PEP_ILLEGAL_VALUE;
     1.7 +    char* own_id = NULL;
     1.8  
     1.9      bool msgIsFromGroup = false;
    1.10      if(sync_msg->is_a_message){
    1.11 @@ -275,16 +276,24 @@
    1.12      // partner identity must be explicitely added DB to later
    1.13      // be able to communicate securely with it.
    1.14      if(partner){
    1.15 +        
    1.16 +        status = get_default_own_userid(session, &own_id);
    1.17 +        
    1.18 +        if (!own_id)
    1.19 +            own_id = strdup(PEP_OWN_USERID);
    1.20 +            
    1.21          // protect virtual user IDs 
    1.22          if((strncmp("TOFU_", partner->user_id, 6) == 0 &&
    1.23             strlen(partner->user_id) == strlen(partner->address) + 6 &&
    1.24             strcmp(partner->user_id + 6, partner->address)) ||
    1.25          // protect own ID 
    1.26 -           (strcmp(PEP_OWN_USERID, partner->user_id) == 0)){
    1.27 +           (strcmp(own_id, partner->user_id) == 0)){
    1.28              status = PEP_SYNC_ILLEGAL_MESSAGE;
    1.29 +            free(own_id);
    1.30              goto error;
    1.31          }
    1.32  
    1.33 +        free(own_id);
    1.34          // partner IDs are UUIDs bound to session lifespan
    1.35          // and therefore partner identities are not supposed
    1.36          // to mutate over time, but just not be used anymore.
    1.37 @@ -349,7 +358,8 @@
    1.38      }
    1.39  
    1.40      free(sync_msg);
    1.41 -
    1.42 +    free(own_id);
    1.43 +    
    1.44      return status;
    1.45  }
    1.46  
    1.47 @@ -426,6 +436,9 @@
    1.48      bool discard = false;
    1.49      bool force_keep_msg = false;
    1.50  
    1.51 +    char* own_id = NULL;
    1.52 +    PEP_STATUS own_id_status = get_default_own_userid(session, &own_id);
    1.53 +
    1.54      for (bloblist_t *bl = src->attachments; bl && bl->value; bl = bl->next) {
    1.55          if (bl->mime_type && strcasecmp(bl->mime_type, "application/pEp.sync") == 0
    1.56                  && bl->size) {
    1.57 @@ -451,11 +464,18 @@
    1.58                              msg->header.me.address->size);
    1.59  
    1.60                  if(null_terminated_address){
    1.61 -                    status = get_identity(session, 
    1.62 -                                          null_terminated_address, 
    1.63 -                                          PEP_OWN_USERID, 
    1.64 -                                          &check_me);
    1.65 -                    free(null_terminated_address);
    1.66 +                    
    1.67 +                    if (own_id) {                        
    1.68 +                        status = get_identity(session, 
    1.69 +                                              null_terminated_address, 
    1.70 +                                              own_id, 
    1.71 +                                              &check_me);
    1.72 +                        free(null_terminated_address);
    1.73 +
    1.74 +                    }
    1.75 +                    else {
    1.76 +                        status = own_id_status;
    1.77 +                    }
    1.78                  } 
    1.79                  else
    1.80                      status = PEP_OUT_OF_MEMORY;
    1.81 @@ -608,10 +628,23 @@
    1.82                              // GroupUpdate and UpdateRequests come from group.
    1.83                              // check trust relation in between signer key and 
    1.84                              // own id to be sure.
    1.85 -                            pEp_identity *_from = new_identity(NULL, 
    1.86 -                                                               keylist->value,
    1.87 -                                                               PEP_OWN_USERID,
    1.88 -                                                               NULL);
    1.89 +                            
    1.90 +                            if (status != PEP_STATUS_OK)
    1.91 +                                goto free_all;
    1.92 +                            
    1.93 +                            pEp_identity* _from = NULL;
    1.94 +                            
    1.95 +                            if (own_id) {    
    1.96 +                                _from = new_identity(NULL, 
    1.97 +                                                     keylist->value,
    1.98 +                                                     own_id,
    1.99 +                                                     NULL);
   1.100 +                            }
   1.101 +                            else {
   1.102 +                                status = own_id_status;
   1.103 +                                goto free_all;
   1.104 +                            }
   1.105 +                            
   1.106                              if (_from == NULL){
   1.107                                  status = PEP_OUT_OF_MEMORY;
   1.108                                  goto free_all;
   1.109 @@ -658,7 +691,7 @@
   1.110                  ASN_STRUCT_FREE(asn_DEF_DeviceGroup_Protocol, msg);
   1.111              free_userid:
   1.112                  free(user_id);
   1.113 -
   1.114 +                free(own_id);
   1.115                  if (status != PEP_STATUS_OK)
   1.116                      return status;
   1.117              }
   1.118 @@ -754,6 +787,7 @@
   1.119      message *_message = NULL;
   1.120      pEp_identity *me = NULL;
   1.121      pEp_identity *_me = NULL;
   1.122 +    char* own_id = NULL;
   1.123  
   1.124      assert(session && partner && state && msg);
   1.125      if (!(session && partner && state && msg))
   1.126 @@ -765,10 +799,14 @@
   1.127          goto error;
   1.128      }
   1.129  
   1.130 +    status = get_default_own_userid(session, &own_id);
   1.131 +    if (status != PEP_STATUS_OK)
   1.132 +        goto error;
   1.133 +
   1.134      msg->header.version.major = SYNC_VERSION_MAJOR;
   1.135      msg->header.version.minor = SYNC_VERSION_MINOR;
   1.136  
   1.137 -    status = get_identity(session, partner->address, PEP_OWN_USERID, &me);
   1.138 +    status = get_identity(session, partner->address, own_id, &me);
   1.139      if (status != PEP_STATUS_OK)
   1.140          goto error;
   1.141      
   1.142 @@ -889,6 +927,7 @@
   1.143      free(payload);
   1.144      free_message(_message);
   1.145      free_identity(me);
   1.146 +    free(own_id);
   1.147      return status;
   1.148  }
   1.149