cleaner sync
authorVolker Birk <vb@pep-project.org>
Fri, 03 May 2019 12:40:18 +0200
branchsync
changeset 36122084f4779e1b
parent 3611 95a05d4cf872
child 3614 fef7884ea3ae
cleaner
src/message_api.c
     1.1 --- a/src/message_api.c	Fri May 03 10:47:43 2019 +0200
     1.2 +++ b/src/message_api.c	Fri May 03 12:40:18 2019 +0200
     1.3 @@ -2900,19 +2900,27 @@
     1.4                                                        message* msg,
     1.5                                                        bool* imported_keys,
     1.6                                                        bool* imported_private,
     1.7 -                                                      identity_list** private_il) {
     1.8 -                                                          
     1.9 +                                                      identity_list** private_il)
    1.10 +{
    1.11 +    assert(src && msg && imported_keys && imported_private);
    1.12 +    if (!(src && msg && imported_keys && imported_private))
    1.13 +        return PEP_ILLEGAL_VALUE;
    1.14 +
    1.15      PEP_STATUS status = PEP_STATUS_OK;
    1.16 -    
    1.17 +    *imported_keys = NULL;
    1.18 +    *imported_private = false;
    1.19 +    if (private_il)
    1.20 +        *private_il = NULL;
    1.21 +
    1.22      // check for private key in decrypted message attachment while importing
    1.23      identity_list *_private_il = NULL;
    1.24 -    *imported_keys = import_attached_keys(session, msg, &_private_il);
    1.25 -    
    1.26 -    if (_private_il && identity_list_length(_private_il) == 1 &&
    1.27 -        _private_il->ident->address)
    1.28 -        *imported_private = true;
    1.29 -
    1.30 -    if (private_il && imported_private) {
    1.31 +
    1.32 +    bool _imported_keys = import_attached_keys(session, msg, &_private_il);
    1.33 +    bool _imported_private = false;
    1.34 +    if (_private_il && _private_il->ident && _private_il->ident->address)
    1.35 +        _imported_private = true;
    1.36 +
    1.37 +    if (private_il && _imported_private) {
    1.38          // the private identity list should NOT be subject to myself() or
    1.39          // update_identity() at this point.
    1.40          // If the receiving app wants them to be in the trust DB, it
    1.41 @@ -2922,27 +2930,30 @@
    1.42          char* own_id = NULL;
    1.43          status = get_default_own_userid(session, &own_id);
    1.44          
    1.45 -        if (status != PEP_STATUS_OK) {
    1.46 -            free(own_id);
    1.47 -            own_id = NULL;
    1.48 -        }
    1.49 -        
    1.50 -        identity_list* il = _private_il;
    1.51 -        for ( ; il; il = il->next) {
    1.52 +        for (identity_list* il = _private_il; il; il = il->next) {
    1.53              if (own_id) {
    1.54                  free(il->ident->user_id);
    1.55                  il->ident->user_id = strdup(own_id);
    1.56 +                assert(il->ident->user_id);
    1.57 +                if (!il->ident->user_id) {
    1.58 +                    status = PEP_OUT_OF_MEMORY;
    1.59 +                    break;
    1.60 +                }
    1.61              }
    1.62              il->ident->me = true;
    1.63          }
    1.64 +        free(own_id);
    1.65          *private_il = _private_il;
    1.66 -        
    1.67 -        free(own_id);
    1.68      }
    1.69 -    else
    1.70 +    else {
    1.71          free_identity_list(_private_il);
    1.72 +    }
    1.73   
    1.74 -    
    1.75 +    if (!status) {
    1.76 +        *imported_keys = _imported_keys;
    1.77 +        *imported_private = _imported_private;
    1.78 +    }
    1.79 +
    1.80      return status;
    1.81  }
    1.82  
    1.83 @@ -3243,7 +3254,7 @@
    1.84  
    1.85  }
    1.86  
    1.87 -DYNAMIC_API PEP_STATUS _decrypt_message(
    1.88 +static PEP_STATUS _decrypt_message(
    1.89          PEP_SESSION session,
    1.90          message *src,
    1.91          message **dst,