Upstream version 10.38.210.0
[platform/framework/web/crosswalk.git] / src / xwalk / application / tools / tizen / xwalk_tizen_user.cc
index 2b89db6..f02e61f 100644 (file)
@@ -11,6 +11,7 @@
 #include <errno.h>
 #include <pwd.h>
 #include <grp.h>
+#include <tzplatform_config.h>
 
 int xwalk_tizen_check_user_app(void) {
   char* buffer = NULL;
@@ -33,7 +34,41 @@ int xwalk_tizen_check_user_app(void) {
   } else {
     if ( (!current_g) || (
         strcmp(current_g->gr_name, "users") &&
-        strcmp(current_g->gr_name, "app"))) {
+        strcmp(current_g->gr_name, "app") )) {
+      fprintf(stderr, "group '%s' is not allowed :",
+          current_g ? current_g->gr_name : "<NULL>");
+      fprintf(stderr, "launching an application will not work\n");
+      free(buffer);
+      return -EINVAL;
+    }
+  }
+  return 0;
+}
+
+int xwalk_tizen_check_user_for_xwalkctl(void) {
+  char* buffer = NULL;
+  int err = 0;
+  struct group grp;
+  struct group* current_g;
+  int64_t len = sysconf(_SC_GETGR_R_SIZE_MAX);
+  if (len == -1)
+    len = 1024;
+  buffer = reinterpret_cast<char*>(malloc((size_t)len));
+  if (!buffer)
+    return -EINVAL;
+
+  err = getgrgid_r(getgid(), &grp, buffer, len, &current_g);
+  if (err) {
+  fprintf(stderr, "group can't be determined");
+    fprintf(stderr, "launching an application will not work\n");
+    free(buffer);
+    return -EINVAL;
+  } else {
+    if ( (!current_g) || (
+        strcmp(current_g->gr_name, "users") &&
+        strcmp(current_g->gr_name, "app") &&
+        (strcmp(current_g->gr_name, "root") &&
+         getuid() == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)))) {
       fprintf(stderr, "group '%s' is not allowed :",
             current_g ? current_g->gr_name : "<NULL>");
       fprintf(stderr, "launching an application will not work\n");