Set ACL Rowner to PT's Device ID in SRPProvisionACL
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / src / secureresourceprovider.c
index d68e4da..3a8f242 100644 (file)
@@ -867,6 +867,25 @@ OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceI
     VERIFY_NON_NULL(TAG, acl, ERROR,  OC_STACK_INVALID_PARAM);
     VERIFY_NON_NULL(TAG, resultCallback, ERROR,  OC_STACK_INVALID_CALLBACK);
 
+    // if rowneruuid is empty, set it to device ID
+    OicUuid_t emptyOwner = {.id = {0} };
+    if (memcmp(&(acl->rownerID.id), &emptyOwner, UUID_IDENTITY_SIZE) == 0)
+    {
+        OIC_LOG(DEBUG, TAG, "Set Rowner to PT's deviceId, because Rowner of ACL is empty");
+        OicUuid_t oicUuid;
+
+        if (OC_STACK_OK == GetDoxmDeviceID(&oicUuid))
+        {
+            memcpy(&(acl->rownerID.id), &oicUuid, UUID_IDENTITY_SIZE);
+        }
+        else
+        {
+            OIC_LOG(DEBUG, TAG, "Failed to set Rowner to PT's deviceID\
+                becuase it failed to retrieve Doxm DeviceID");
+            return OC_STACK_ERROR;
+        }
+    }
+
     OCSecurityPayload* secPayload = (OCSecurityPayload*)OICCalloc(1, sizeof(OCSecurityPayload));
     if(!secPayload)
     {
@@ -2366,7 +2385,7 @@ OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
         goto error;
     }
     OIC_LOG_V(DEBUG, TAG, "Query=%s", query);
-    
+
     OCCallbackData cbData = { .context = NULL, .cb = NULL, .cd = NULL };
     OCMethod method = OC_REST_POST;
     OCDoHandle handle = NULL;