ENGINE-289: changed initialise_own_identities to deal with default user_id aliases ENGINE-289
authorKrista Bennett <krista@pep-project.org>
Wed, 17 Jan 2018 12:39:10 +0100
branchENGINE-289
changeset 2404ba45f3303e5f
parent 2403 6091e86174d7
child 2405 f723208869f7
ENGINE-289: changed initialise_own_identities to deal with default user_id aliases
src/keymanagement.c
     1.1 --- a/src/keymanagement.c	Wed Jan 17 12:25:49 2018 +0100
     1.2 +++ b/src/keymanagement.c	Wed Jan 17 12:39:10 2018 +0100
     1.3 @@ -928,8 +928,11 @@
     1.4      if (!session)
     1.5          return PEP_ILLEGAL_VALUE;
     1.6          
     1.7 -    char* stored_own_userid = NULL;
     1.8 -    get_default_own_userid(session, &stored_own_userid);
     1.9 +    if (!my_idents)
    1.10 +        return PEP_STATUS_OK;
    1.11 +        
    1.12 +    char* default_own_userid = NULL;
    1.13 +    get_default_own_userid(session, &default_own_userid);
    1.14      
    1.15      identity_list* ident_curr = my_idents;
    1.16      while (ident_curr) {
    1.17 @@ -937,27 +940,32 @@
    1.18          if (!ident)
    1.19              return PEP_ILLEGAL_VALUE;
    1.20              
    1.21 -        if (stored_own_userid) {
    1.22 -            if (!ident->user_id) 
    1.23 -                ident->user_id = strdup(stored_own_userid);
    1.24 -            else if (strcmp(stored_own_userid, ident->user_id) != 0)
    1.25 -                return PEP_ILLEGAL_VALUE;
    1.26 +        if (default_own_userid) {
    1.27 +            if (ident->user_id && strcmp(default_own_userid, ident->user_id) != 0) {
    1.28 +                status = set_userid_alias(session, default_own_userid, ident->user_id);
    1.29 +                if (status != PEP_STATUS_OK)
    1.30 +                    goto pep_free;
    1.31 +                free(ident->user_id);
    1.32 +            }
    1.33 +            ident->user_id = strdup(default_own_userid);        
    1.34          }
    1.35          else if (!ident->user_id) {
    1.36 -            stored_own_userid = PEP_OWN_USERID;
    1.37 +            default_own_userid = PEP_OWN_USERID;
    1.38              ident->user_id = strdup(PEP_OWN_USERID);
    1.39          }
    1.40          
    1.41 -        ident->me = true; // Just in case.
    1.42 +        ident->me = true;
    1.43          
    1.44          // Ok, do it...
    1.45          status = set_identity(session, ident);
    1.46          if (status != PEP_STATUS_OK)
    1.47 -            return status;
    1.48 +            goto pep_free;
    1.49          
    1.50          ident_curr = ident_curr->next;
    1.51      }
    1.52      
    1.53 +pep_free:
    1.54 +    free(default_own_userid);
    1.55      return status;
    1.56  }
    1.57