[widget-viewer-dali] Change the license as Flora
[platform/core/uifw/widget-viewer-dali.git] / internal / widget_view_manager / widget_view_manager_impl.cpp
index 4f9ef78..41092d0 100644 (file)
@@ -1,18 +1,18 @@
 /*
+ * Samsung API
  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
- * Licensed under the Apache License, Version 2.0 (the "License");
+ * Licensed under the Flora License, Version 1.1 (the License);
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://floralicense.org/license/
  *
  * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
+ * distributed under the License is distributed on an AS IS BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- *
  */
 
 // CLASS HEADER
 // EXTERNAL INCLUDES
 #include <dali/integration-api/debug.h>
 #include <system_info.h>
+#include <cynara-client.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
 #include <widget_errno.h>
 #include <widget_instance.h>
 
@@ -39,11 +43,13 @@ namespace Internal
 namespace
 {
 
+#define SMACK_LABEL_LENGTH 255
+
 #if defined(DEBUG_ENABLED)
 Integration::Log::Filter* gWidgetViewManagerLogging  = Integration::Log::Filter::New( Debug::Verbose, false, "LOG_WIDGET_VIEW_MANAGER" );
 #endif
 
-static inline bool IsWidgetFeatureEnabled()
+static bool IsWidgetFeatureEnabled()
 {
   static bool feature = false;
   static bool retrieved = false;
@@ -63,6 +69,52 @@ static inline bool IsWidgetFeatureEnabled()
   return feature;
 }
 
+static bool CheckPrivilege( const char* privilege )
+{
+  cynara* cynara;
+  int fd = 0;
+  int ret = 0;
+  char subjectLabel[SMACK_LABEL_LENGTH + 1] = "";
+  char uid[10] = { 0, };
+  const char* clientSession = "";
+
+  ret = cynara_initialize( &cynara, NULL );
+  if( ret != CYNARA_API_SUCCESS )
+  {
+    return false;
+  }
+
+  fd = open( "/proc/self/attr/current", O_RDONLY );
+  if( fd < 0 )
+  {
+    cynara_finish( cynara );
+    return false;
+  }
+
+  ret = read( fd, subjectLabel, SMACK_LABEL_LENGTH );
+  if( ret < 0 )
+  {
+    close( fd );
+    cynara_finish( cynara );
+    return false;
+  }
+
+  close( fd );
+
+  snprintf( uid, 10, "%d", getuid() );
+
+  ret = cynara_check( cynara, subjectLabel, clientSession, uid, privilege );
+  if( ret != CYNARA_API_ACCESS_ALLOWED )
+  {
+    cynara_finish( cynara );
+    return false;
+  }
+
+  cynara_finish( cynara );
+
+  return true;
+}
+
 } // unnamed namespace
 
 WidgetViewManagerPtr WidgetViewManager::New( Application application, const std::string& name )
@@ -97,6 +149,12 @@ int WidgetViewManager::Initialize( Application application, const std::string& n
     return WIDGET_ERROR_NOT_SUPPORTED;
   }
 
+  if( !CheckPrivilege( "http://tizen.org/privilege/widget.viewer" ) )
+  {
+    DALI_LOG_INFO( gWidgetViewManagerLogging, Debug::Verbose, "WidgetViewManager::Initialize: Privilege error.\n" );
+    return WIDGET_ERROR_PERMISSION_DENIED;
+  }
+
   // create compositor
   mCompositor = Pepper::Compositor::New( application, name );