|
|
|
@ -72,6 +72,60 @@ enomem:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEP_STATUS add_sticky_bit_to_Identity(PEP_SESSION session, Identity_t *ident)
|
|
|
|
|
{
|
|
|
|
|
assert(session && ident);
|
|
|
|
|
if (!(session && ident))
|
|
|
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
|
|
PEP_STATUS status = PEP_STATUS_OK;
|
|
|
|
|
|
|
|
|
|
char *fpr = NULL;
|
|
|
|
|
char *user_id = NULL;
|
|
|
|
|
BOOLEAN_t *sticky = NULL;
|
|
|
|
|
|
|
|
|
|
fpr = strndup((char *) ident->fpr.buf, ident->fpr.size);
|
|
|
|
|
assert(fpr);
|
|
|
|
|
if (!fpr)
|
|
|
|
|
goto enomem;
|
|
|
|
|
|
|
|
|
|
user_id = strndup((char *) ident->user_id.buf, ident->user_id.size);
|
|
|
|
|
assert(user_id);
|
|
|
|
|
if (!user_id)
|
|
|
|
|
goto enomem;
|
|
|
|
|
|
|
|
|
|
sticky = (BOOLEAN_t *) calloc(1, sizeof(BOOLEAN_t));
|
|
|
|
|
assert(sticky);
|
|
|
|
|
if (!sticky)
|
|
|
|
|
goto enomem;
|
|
|
|
|
|
|
|
|
|
bool _sticky = false;
|
|
|
|
|
status = get_key_sticky_bit_for_user(session, user_id, fpr, &_sticky);
|
|
|
|
|
if (status) {
|
|
|
|
|
if (status == PEP_KEY_NOT_FOUND)
|
|
|
|
|
_sticky = false;
|
|
|
|
|
else
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*sticky = _sticky;
|
|
|
|
|
|
|
|
|
|
ident->sticky = sticky;
|
|
|
|
|
free(fpr);
|
|
|
|
|
free(user_id);
|
|
|
|
|
|
|
|
|
|
return PEP_STATUS_OK;
|
|
|
|
|
|
|
|
|
|
enomem:
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
free(fpr);
|
|
|
|
|
free(user_id);
|
|
|
|
|
free(sticky);
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pEp_identity *Identity_to_Struct(Identity_t *ident, pEp_identity *result)
|
|
|
|
|
{
|
|
|
|
|
bool allocated = !result;
|
|
|
|
@ -124,6 +178,99 @@ enomem:
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PEP_STATUS set_new_own_key_if_not_sticky(PEP_SESSION session, Identity_t *ident)
|
|
|
|
|
{
|
|
|
|
|
assert(session && ident);
|
|
|
|
|
if (!(session && ident))
|
|
|
|
|
return PEP_ILLEGAL_VALUE;
|
|
|
|
|
|
|
|
|
|
PEP_STATUS status = PEP_STATUS_OK;
|
|
|
|
|
|
|
|
|
|
pEp_identity *_new = NULL;
|
|
|
|
|
pEp_identity *_old = NULL;
|
|
|
|
|
char *own_user_id = NULL;
|
|
|
|
|
|
|
|
|
|
_new = Identity_to_Struct(ident, NULL);
|
|
|
|
|
if (!_new)
|
|
|
|
|
goto enomem;
|
|
|
|
|
bool new_is_sticky = ident->sticky && *ident->sticky;
|
|
|
|
|
|
|
|
|
|
if (EMPTYSTR(_new->address) || EMPTYSTR(_new->fpr)) {
|
|
|
|
|
status = PEP_ILLEGAL_VALUE;
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = get_default_own_userid(session, &own_user_id);
|
|
|
|
|
if (status) {
|
|
|
|
|
if (status == PEP_CANNOT_FIND_IDENTITY) {
|
|
|
|
|
own_user_id = strdup(PEP_OWN_USERID);
|
|
|
|
|
assert(own_user_id);
|
|
|
|
|
if (!own_user_id)
|
|
|
|
|
goto enomem;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = get_identity(session, _new->address, own_user_id, &_old);
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PEP_STATUS_OK: {
|
|
|
|
|
assert(_old);
|
|
|
|
|
|
|
|
|
|
if (!EMPTYSTR(_old->fpr)) {
|
|
|
|
|
if (!new_is_sticky && strcasecmp(_new->fpr, _old->fpr) == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool old_is_sticky = false;
|
|
|
|
|
if (!EMPTYSTR(_old->fpr)) {
|
|
|
|
|
status = get_key_sticky_bit_for_user(session, own_user_id, _old->fpr, &old_is_sticky);
|
|
|
|
|
if (status) {
|
|
|
|
|
if (status == PEP_KEY_NOT_FOUND) {
|
|
|
|
|
old_is_sticky = false;
|
|
|
|
|
status = PEP_STATUS_OK;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (old_is_sticky)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status = set_own_imported_key(session, _old, _new->fpr, new_is_sticky);
|
|
|
|
|
if (status)
|
|
|
|
|
goto error;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case PEP_CANNOT_FIND_IDENTITY:
|
|
|
|
|
status = set_own_imported_key(session, _new, _new->fpr, new_is_sticky);
|
|
|
|
|
if (status)
|
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
goto error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
free_identity(_new);
|
|
|
|
|
free_identity(_old);
|
|
|
|
|
free(own_user_id);
|
|
|
|
|
|
|
|
|
|
return PEP_STATUS_OK;
|
|
|
|
|
|
|
|
|
|
enomem:
|
|
|
|
|
status = PEP_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
free_identity(_new);
|
|
|
|
|
free_identity(_old);
|
|
|
|
|
free(own_user_id);
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IdentityList_t *IdentityList_from_identity_list(
|
|
|
|
|
const identity_list *list,
|
|
|
|
|
IdentityList_t *result
|
|
|
|
|