Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
linux访问系统调用未按预期工作_Linux_Java Native Interface_File Permissions_Setfsuid - Fatal编程技术网

linux访问系统调用未按预期工作

linux访问系统调用未按预期工作,linux,java-native-interface,file-permissions,setfsuid,Linux,Java Native Interface,File Permissions,Setfsuid,我正在尝试根据java web应用程序中登录的用户执行文件操作。为此,我使用JNI本机实现将fs uid和fs gid设置为登录用户的uid和gid。现在,仅当登录用户具有权限时才允许文件操作 我还想检索登录用户是否具有文件的读/写/执行权限。试图使用access、faccessat系统调用,但它们似乎没有使用fs uid 如何获得登录用户的文件权限?找到了一种简单的解决方法。不知道它有多完整。它不考虑ACL struct passwd *pw = getpwnam(userName); if

我正在尝试根据java web应用程序中登录的用户执行文件操作。为此,我使用JNI本机实现将fs uid和fs gid设置为登录用户的uid和gid。现在,仅当登录用户具有权限时才允许文件操作

我还想检索登录用户是否具有文件的读/写/执行权限。试图使用access、faccessat系统调用,但它们似乎没有使用fs uid


如何获得登录用户的文件权限?

找到了一种简单的解决方法。不知道它有多完整。它不考虑ACL

struct passwd *pw = getpwnam(userName);
if (pw == NULL) {
    return NULL;
}
jint fill[3];//rwx - 1 indicates success, 0 indicates failure
if(pw->pw_uid == 0) {
    fill[0] = fill[1] = fill[2] = 1;
} else {
    struct stat info;
    stat(path, &info);
    int mode = info.st_mode;

    if(pw->pw_uid == info.st_uid) {
        fill[0] = mode & S_IRUSR ? 1 : 0;    /* 3 bits for user  */
        fill[1] = mode & S_IWUSR ? 1 : 0;
        fill[2] = mode & S_IXUSR ? 1 : 0;
    } else if(pw->pw_gid == info.st_gid) {
        fill[0] = mode & S_IRGRP ? 1 : 0;    /* 3 bits for group  */
        fill[1] = mode & S_IWGRP ? 1 : 0;
        fill[2] = mode & S_IXGRP ? 1 : 0;
    } else {
        fill[0] = mode & S_IROTH ? 1 : 0;    /* 3 bits for group  */
        fill[1] = mode & S_IWOTH ? 1 : 0;
        fill[2] = mode & S_IXOTH ? 1 : 0;
    }
}

一个相关的问题-。但是,解决方案并没有说明如何获取文件权限。在尝试操作之前,我需要能够检测操作是否可行。如果将setuid设置为登录用户,则无法重置原始uid。看起来没有办法做到这一点: