#include <errno.h>
#include <pwd.h>
#include <grp.h>
+#include <tzplatform_config.h>
int xwalk_tizen_check_user_app(void) {
char* buffer = NULL;
} 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, ¤t_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");