bugfix: when identity is not stored yet, update_identity failes
authorvb
Wed, 20 Aug 2014 16:11:46 +0200
changeset 2189f925c7d5be
parent 20 63ff31d0cfbd
child 22 e235409d570a
bugfix: when identity is not stored yet, update_identity failes
src/keymanagement.c
src/keymanagement.h
     1.1 --- a/src/keymanagement.c	Mon Aug 11 16:49:42 2014 +0200
     1.2 +++ b/src/keymanagement.c	Wed Aug 20 16:11:46 2014 +0200
     1.3 @@ -30,7 +30,7 @@
     1.4  
     1.5      assert(session);
     1.6      assert(identity);
     1.7 -    assert(identity->address);
     1.8 +    assert(!EMPTY(identity->address));
     1.9  
    1.10      status = get_identity(session, identity->address, &stored_identity);
    1.11      assert(status != PEP_OUT_OF_MEMORY);
    1.12 @@ -78,6 +78,78 @@
    1.13                  identity->comm_type = PEP_ct_unknown;
    1.14          }
    1.15  
    1.16 +        if (identity->lang[0] == 0) {
    1.17 +            identity->lang[0] = stored_identity->lang[0];
    1.18 +            identity->lang[1] = stored_identity->lang[1];
    1.19 +            identity->lang[2] = 0;
    1.20 +        }
    1.21 +    }
    1.22 +    else /* stored_identity == NULL */ {
    1.23 +        if (!EMPTY(identity->fpr)) {
    1.24 +            PEP_comm_type _comm_type_key;
    1.25 +
    1.26 +            status = get_key_rating(session, identity->fpr, &_comm_type_key);
    1.27 +            assert(status != PEP_OUT_OF_MEMORY);
    1.28 +            if (status == PEP_OUT_OF_MEMORY)
    1.29 +                return PEP_OUT_OF_MEMORY;
    1.30 +
    1.31 +            identity->comm_type = _comm_type_key;
    1.32 +        }
    1.33 +        else /* EMPTY(identity->fpr) */ {
    1.34 +            PEP_STATUS status;
    1.35 +            stringlist_t *keylist;
    1.36 +            char *_fpr = NULL;
    1.37 +            identity->comm_type = PEP_ct_unknown;
    1.38 +
    1.39 +            status = find_keys(session, identity->address, &keylist);
    1.40 +            assert(status != PEP_OUT_OF_MEMORY);
    1.41 +            if (status == PEP_OUT_OF_MEMORY)
    1.42 +                return PEP_OUT_OF_MEMORY;
    1.43 +
    1.44 +            stringlist_t *_keylist;
    1.45 +            for (_keylist = keylist; _keylist && _keylist->value; _keylist = _keylist->next) {
    1.46 +                PEP_comm_type _comm_type_key;
    1.47 +
    1.48 +                status = get_key_rating(session, _keylist->value, &_comm_type_key);
    1.49 +                assert(status != PEP_OUT_OF_MEMORY);
    1.50 +                if (status == PEP_OUT_OF_MEMORY) {
    1.51 +                    free_stringlist(keylist);
    1.52 +                    return PEP_OUT_OF_MEMORY;
    1.53 +                }
    1.54 +
    1.55 +                if (identity->comm_type == PEP_ct_unknown) {
    1.56 +                    if (_comm_type_key != PEP_ct_compromized && _comm_type_key != PEP_ct_unknown) {
    1.57 +                        identity->comm_type = _comm_type_key;
    1.58 +                        _fpr = _keylist->value;
    1.59 +                    }
    1.60 +                }
    1.61 +                else {
    1.62 +                    if (_comm_type_key != PEP_ct_compromized && _comm_type_key != PEP_ct_unknown) {
    1.63 +                        if (_comm_type_key > identity->comm_type) {
    1.64 +                            identity->comm_type = _comm_type_key;
    1.65 +                            _fpr = _keylist->value;
    1.66 +                        }
    1.67 +                    }
    1.68 +                }
    1.69 +            }
    1.70 +
    1.71 +            if (_fpr) {
    1.72 +                free(identity->fpr);
    1.73 +
    1.74 +                identity->fpr = strdup(_fpr);
    1.75 +                if (identity->fpr == NULL) {
    1.76 +                    free_stringlist(keylist);
    1.77 +                    return PEP_OUT_OF_MEMORY;
    1.78 +                }
    1.79 +                identity->fpr_size = strlen(identity->fpr);
    1.80 +            }
    1.81 +            free_stringlist(keylist);
    1.82 +        }
    1.83 +    }
    1.84 +
    1.85 +    status = PEP_STATUS_OK;
    1.86 +
    1.87 +    if (identity->comm_type != PEP_ct_unknown && !EMPTY(identity->user_id)) {
    1.88          if (EMPTY(identity->username)) {
    1.89              free(identity->username);
    1.90              identity->username = strdup(stored_identity->username);
    1.91 @@ -87,28 +159,6 @@
    1.92              identity->username_size = stored_identity->username_size;
    1.93          }
    1.94  
    1.95 -        if (EMPTY(identity->user_id)) {
    1.96 -            free(identity->user_id);
    1.97 -            identity->user_id = strdup(stored_identity->user_id);
    1.98 -            assert(identity->user_id);
    1.99 -            if (identity->user_id == NULL)
   1.100 -                return PEP_OUT_OF_MEMORY;
   1.101 -            identity->user_id_size = stored_identity->user_id_size;
   1.102 -        }
   1.103 -
   1.104 -        if (identity->lang[0] == 0) {
   1.105 -            identity->lang[0] = stored_identity->lang[0];
   1.106 -            identity->lang[1] = stored_identity->lang[1];
   1.107 -            identity->lang[2] = 0;
   1.108 -        }
   1.109 -    }
   1.110 -    else /* stored_identity == NULL */ {
   1.111 -        identity->comm_type = PEP_ct_unknown;
   1.112 -    }
   1.113 -
   1.114 -    status = PEP_STATUS_OK;
   1.115 -
   1.116 -    if (identity->comm_type != PEP_ct_unknown) {
   1.117          status = set_identity(session, identity);
   1.118          assert(status == PEP_STATUS_OK);
   1.119      }
     2.1 --- a/src/keymanagement.h	Mon Aug 11 16:49:42 2014 +0200
     2.2 +++ b/src/keymanagement.h	Wed Aug 20 16:11:46 2014 +0200
     2.3 @@ -13,7 +13,7 @@
     2.4  //      identity->comm_type, the caller must insert the identity into the
     2.5  //      asynchronous management implementation, so retrieve_next_identity()
     2.6  //      will return this identity later
     2.7 -//      at least identity->address must be a valid UTF-8 string as input
     2.8 +//      at least identity->address must be a non-empty UTF-8 string as input
     2.9  
    2.10  DYNAMIC_API PEP_STATUS update_identity(
    2.11          PEP_SESSION session, pEp_identity * identity