[IOT-2424] Fixed non-UUID subject rowner.
authorNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Fri, 23 Jun 2017 21:55:49 +0000 (14:55 -0700)
committerNathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Mon, 26 Jun 2017 23:42:07 +0000 (23:42 +0000)
Also added additional debug logging to rowner check.

Change-Id: Ic6c2849ebe9519568e789b2a4b34e40252746474
Signed-off-by: Nathan Heldt-Sheller <nathan.heldt-sheller@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/20977
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
Reviewed-by: Kevin Kane <kkane@microsoft.com>
Reviewed-by: Alex Kelley <alexke@microsoft.com>
resource/csdk/security/src/policyengine.c

index 006956a..88b652b 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "utlist.h"
 #include "oic_malloc.h"
+#include "ocrandom.h"
 #include "policyengine.h"
 #include "resourcemanager.h"
 #include "securevirtualresourcetypes.h"
@@ -241,9 +242,17 @@ bool IsRequestFromResourceOwner(SRMRequestContext_t *context)
     bool retVal = false;
     OicUuid_t resourceOwner;
 
-    if(NULL == context)
+    if (NULL == context)
     {
-        return false;
+        retVal = false;
+        goto exit;
+    }
+
+    if (SUBJECT_ID_TYPE_UUID != context->subjectIdType)
+    {
+        OIC_LOG_V(DEBUG, TAG, "%s: Non-UUID subject type cannot be rowner.", __func__);
+        retVal = false;
+        goto exit;
     }
 
     if (IsNilUuid(&context->subjectUuid))
@@ -257,9 +266,37 @@ bool IsRequestFromResourceOwner(SRMRequestContext_t *context)
     if((OIC_R_ACL_TYPE <= context->resourceType) && \
         (OIC_SEC_SVR_TYPE_COUNT > context->resourceType))
     {
-        GetSvrRownerId_t getRownerId = GetSvrRownerId[(int)context->resourceType];
+        GetSvrRownerId_t getRownerId = NULL;
+        OCStackResult getRownerResult = OC_STACK_ERROR;
+
+        getRownerId = GetSvrRownerId[(int)context->resourceType];
+
+        if (NULL != getRownerId)
+        {
+            getRownerResult = getRownerId(&resourceOwner);
+        }
+
+#ifndef NDEBUG // if debug build, log the IDs being used for matching rowner
+        char strUuid[UUID_STRING_SIZE] = "UUID_ERROR";
+        if (OCConvertUuidToString(context->subjectUuid.id, strUuid))
+        {
+            OIC_LOG_V(DEBUG, TAG, "context->subjectUuid for request: %s.", strUuid);
+        }
+        else
+        {
+            OIC_LOG(ERROR, TAG, "failed to convert context->subjectUuid to str.");
+        }
+        if (OCConvertUuidToString(resourceOwner.id, strUuid))
+        {
+            OIC_LOG_V(DEBUG, TAG, "rowneruuid for requested SVR: %s.", strUuid);
+        }
+        else
+        {
+            OIC_LOG(ERROR, TAG, "failed to convert rowneruuid to str.");
+        }
+#endif
 
-        if((NULL != getRownerId) && (OC_STACK_OK == getRownerId(&resourceOwner)))
+        if(OC_STACK_OK == getRownerResult)
         {
             retVal = UuidCmp(&context->subjectUuid, &resourceOwner);
         }