Skip to content

Commit

Permalink
Fix inconsistent ownership validation and resources reset in IoTivity…
Browse files Browse the repository at this point in the history
…-Lite
  • Loading branch information
sp-milos committed May 30, 2024
1 parent 4dd98e5 commit c27a4a6
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions api/oc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#endif /* OC_COLLECTIONS && OC_SERVER && OC_COLLECTIONS_IF_CREATE */

#ifdef OC_SECURITY
#include "oc_storage_internal.h"
#include "oc_store.h"
#include "security/oc_acl_internal.h"
#include "security/oc_ael_internal.h"
Expand Down Expand Up @@ -271,6 +272,23 @@ main_init_resources(void)
#endif /* OC_SOFTWARE_UPDATE */
}

#ifdef OC_SECURITY
static void
main_set_resource_defaults(size_t device)
{
oc_storage_data_clear("u_ids", device);
oc_storage_data_clear("pstat", device);
oc_storage_data_clear("cred", device);
oc_storage_data_clear("acl", device);
oc_storage_data_clear(OCF_SEC_SP_STORE_NAME, device);
oc_storage_data_clear("ael", device);
oc_storage_data_clear(OCF_SEC_SDI_STORE_NAME, device);
#ifdef OC_SOFTWARE_UPDATE
oc_storage_data_clear(OCF_SW_UPDATE_STORE_NAME, device);
#endif /* OC_SOFTWARE_UPDATE */
}
#endif /* OC_SECURITY */

static void
main_load_resources(void)
{
Expand All @@ -282,11 +300,15 @@ main_load_resources(void)
#if defined(OC_SECURITY) || defined(OC_SOFTWARE_UPDATE)
for (size_t device = 0; device < oc_core_get_num_devices(); device++) {
#ifdef OC_SECURITY
OC_DBG("oc_main_init(): loading doxm(%zu)", device);
oc_sec_load_doxm(device);
const oc_sec_doxm_t *doxm = oc_sec_get_doxm(device);
if (!doxm->owned) {
main_set_resource_defaults(device);
}
oc_sec_load_unique_ids(device);
OC_DBG("oc_main_init(): loading pstat(%zu)", device);
oc_sec_load_pstat(device);
OC_DBG("oc_main_init(): loading doxm(%zu)", device);
oc_sec_load_doxm(device);
OC_DBG("oc_main_init(): loading cred(%zu)", device);
oc_sec_load_cred(device);
OC_DBG("oc_main_init(): loading acl(%zu)", device);
Expand Down

0 comments on commit c27a4a6

Please sign in to comment.