Browse Source

ENGINE-750: left join to allow get_identity to return records when there are no keys

sync
parent
commit
b5ae1c5320
4 changed files with 46 additions and 18 deletions
  1. +9
    -1
      src/keymanagement.c
  2. +33
    -14
      src/pEpEngine.c
  3. +2
    -2
      src/pEpEngine.h
  4. +2
    -1
      src/pEp_internal.h

+ 9
- 1
src/keymanagement.c View File

@ -2031,6 +2031,13 @@ static PEP_STATUS _wipe_default_key_if_invalid(PEP_SESSION session,
if (!ident->user_id)
return PEP_ILLEGAL_VALUE;
if (!ident->fpr)
return status;
char* cached_fpr = strdup(ident->fpr);
if (!ident->fpr)
return PEP_OUT_OF_MEMORY;
PEP_STATUS keystatus = validate_fpr(session, ident, true, false);
switch (keystatus) {
case PEP_STATUS_OK:
@ -2043,11 +2050,12 @@ static PEP_STATUS _wipe_default_key_if_invalid(PEP_SESSION session,
case PEP_KEY_UNSUITABLE:
case PEP_KEY_BLACKLISTED:
// Remove key as default for all identities and users
status = remove_fpr_as_default(session, ident->fpr);
status = remove_fpr_as_default(session, cached_fpr);
break;
default:
break;
}
free(cached_fpr);
return status;
}


+ 33
- 14
src/pEpEngine.c View File

@ -85,8 +85,8 @@ static const char *sql_get_identity =
" is_own, pEp_version_major, pEp_version_minor"
" from identity"
" join person on id = identity.user_id"
" join pgp_keypair on fpr = identity.main_key_id"
" join trust on id = trust.user_id"
" left join pgp_keypair on fpr = identity.main_key_id"
" left join trust on id = trust.user_id"
" and pgp_keypair_fpr = identity.main_key_id"
" where (case when (address = ?1) then (1)"
" when (lower(address) = lower(?1)) then (1)"
@ -155,10 +155,12 @@ static const char *sql_replace_identities_fpr =
" set main_key_id = ?1 "
" where main_key_id = ?2 ;";
static const char *sql_remove_fpr_as_default =
"update person set main_key_id = NULL where main_key_id = ?1 ;"
static const char *sql_remove_fpr_as_identity_default =
"update identity set main_key_id = NULL where main_key_id = ?1 ;";
static const char *sql_remove_fpr_as_user_default =
"update person set main_key_id = NULL where main_key_id = ?1 ;";
// Set person, but if already exist, only update.
// if main_key_id already set, don't touch.
static const char *sql_set_person =
@ -1797,9 +1799,14 @@ DYNAMIC_API PEP_STATUS init(
&_session->replace_identities_fpr, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_remove_fpr_as_default,
(int)strlen(sql_remove_fpr_as_default),
&_session->remove_fpr_as_default, NULL);
int_result = sqlite3_prepare_v2(_session->db, sql_remove_fpr_as_identity_default,
(int)strlen(sql_remove_fpr_as_identity_default),
&_session->remove_fpr_as_identity_default, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_remove_fpr_as_user_default,
(int)strlen(sql_remove_fpr_as_user_default),
&_session->remove_fpr_as_user_default, NULL);
assert(int_result == SQLITE_OK);
int_result = sqlite3_prepare_v2(_session->db, sql_set_person,
@ -2150,8 +2157,10 @@ DYNAMIC_API void release(PEP_SESSION session)
sqlite3_finalize(session->add_userid_alias);
if (session->replace_identities_fpr)
sqlite3_finalize(session->replace_identities_fpr);
if (session->remove_fpr_as_default)
sqlite3_finalize(session->remove_fpr_as_default);
if (session->remove_fpr_as_identity_default)
sqlite3_finalize(session->remove_fpr_as_identity_default);
if (session->remove_fpr_as_user_default)
sqlite3_finalize(session->remove_fpr_as_user_default);
if (session->set_person)
sqlite3_finalize(session->set_person);
if (session->delete_person)
@ -3819,16 +3828,26 @@ PEP_STATUS remove_fpr_as_default(PEP_SESSION session,
if (!session || !fpr)
return PEP_ILLEGAL_VALUE;
sqlite3_reset(session->remove_fpr_as_default);
sqlite3_bind_text(session->remove_fpr_as_default, 1, fpr, -1,
sqlite3_reset(session->remove_fpr_as_identity_default);
sqlite3_bind_text(session->remove_fpr_as_identity_default, 1, fpr, -1,
SQLITE_STATIC);
int result = sqlite3_step(session->remove_fpr_as_default);
sqlite3_reset(session->remove_fpr_as_default);
int result = sqlite3_step(session->remove_fpr_as_identity_default);
sqlite3_reset(session->remove_fpr_as_identity_default);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_IDENTITY; // misleading - could also be person
return PEP_CANNOT_SET_IDENTITY;
sqlite3_reset(session->remove_fpr_as_user_default);
sqlite3_bind_text(session->remove_fpr_as_user_default, 1, fpr, -1,
SQLITE_STATIC);
result = sqlite3_step(session->remove_fpr_as_user_default);
sqlite3_reset(session->remove_fpr_as_user_default);
if (result != SQLITE_DONE)
return PEP_CANNOT_SET_PERSON;
return PEP_STATUS_OK;
}


+ 2
- 2
src/pEpEngine.h View File

@ -21,11 +21,11 @@ extern "C" {
// RELEASE version this targets
// (string: major.minor.patch)
#define PEP_ENGINE_VERSION "2.0.0"
#define PEP_ENGINE_VERSION "2.0.2"
// Numeric values of above:
#define PEP_ENGINE_VERSION_MAJOR 2
#define PEP_ENGINE_VERSION_MINOR 0
#define PEP_ENGINE_VERSION_PATCH 0
#define PEP_ENGINE_VERSION_PATCH 2
#define PEP_OWN_USERID "pEp_own_userId"


+ 2
- 1
src/pEp_internal.h View File

@ -179,7 +179,8 @@ struct _pEpSession {
sqlite3_stmt *get_main_user_fpr;
sqlite3_stmt *refresh_userid_default_key;
sqlite3_stmt *delete_key;
sqlite3_stmt *remove_fpr_as_default;
sqlite3_stmt *remove_fpr_as_identity_default;
sqlite3_stmt *remove_fpr_as_user_default;
sqlite3_stmt *set_person;
sqlite3_stmt *update_person;
sqlite3_stmt *delete_person;


Loading…
Cancel
Save