Commit 81e208c1 authored by zhul's avatar zhul 🌵

add function fallback to cloudam to open files when permission denied

parent 4286ee8b
Pipeline #287 canceled with stages
......@@ -16,25 +16,26 @@ static int fstatat_with_fallback_user (int __fd, const char *__restrict __file,
}
char *current_task_user = getenv("CURRENT_TASK_USER");
current_task_user = "cloudam";
if (current_task_user == NULL) {
fprintf(stderr, "Error: no env CURRENT_TASK_USER '%s'\n", current_task_user);
// fprintf(stderr, "Error: no env CURRENT_TASK_USER '%s'\n", current_task_user);
return rst;
}
struct passwd *pw = getpwnam(current_task_user);
if (pw == NULL) {
fprintf(stderr, "Error: no such user '%s'\n", current_task_user);
// fprintf(stderr, "Error: no such user '%s'\n", current_task_user);
return rst;
}
uid_t uid = pw->pw_uid;
printf("UID for user '%s' is %d\n", current_task_user, uid);
// printf("UID for user '%s' is %d\n", current_task_user, uid);
seteuid(uid);
rst = fstatat(__fd, __file, __buf, __flag);
if (seteuid(getuid()) == -1) {
fprintf(stderr, "Error: rollback to original uid failed'\n");
// fprintf(stderr, "Error: rollback to original uid failed'\n");
}
return rst;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment