提交 56a95b9e 编写于 作者: C chenjing

fix: 修复内核access chmod chown接口

1、修复内核的access chmod chown功能;
2、此三个接口的syscall直接调用内核态接口执行操作。

close #I3Z5L6
Signed-off-by: Nchenjing <chenjing139@huawei.com>
Change-Id: I301f00fb341252b697b04b9970db86f0e7f978df
上级 00381028
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
#include "dirent.h" #include "dirent.h"
#include "unistd.h" #include "unistd.h"
#include "sys/select.h" #include "sys/select.h"
#include "sys/mount.h"
#include "sys/stat.h" #include "sys/stat.h"
#include "sys/statfs.h"
#include "sys/prctl.h" #include "sys/prctl.h"
#include "fs/fd_table.h" #include "fs/fd_table.h"
#include "fs/file.h" #include "fs/file.h"
...@@ -256,30 +258,70 @@ char *getcwd(char *buf, size_t n) ...@@ -256,30 +258,70 @@ char *getcwd(char *buf, size_t n)
int chmod(const char *path, mode_t mode) int chmod(const char *path, mode_t mode)
{ {
int result; struct IATTR attr = {0};
struct stat buf; attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
int ret;
result = stat(path, &buf); ret = chattr(path, &attr);
if (result != ENOERR) { if (ret < 0) {
return VFS_ERROR;
}
return OK;
}
int chown(const char *pathname, uid_t owner, gid_t group)
{
struct IATTR attr = {0};
attr.attr_chg_valid = 0;
int ret;
if (owner != (uid_t)-1) {
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
}
if (group != (gid_t)-1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
ret = chattr(pathname, &attr);
if (ret < 0) {
return VFS_ERROR; return VFS_ERROR;
} }
/* no access/permission control for files now, just return OK if stat is okay*/
return OK; return OK;
} }
int access(const char *path, int amode) int access(const char *path, int amode)
{ {
int result; int ret;
struct stat buf; struct stat buf;
struct statfs fsBuf;
result = stat(path, &buf); ret = statfs(path, &fsBuf);
if (ret != 0) {
if (get_errno() != ENOSYS) {
return VFS_ERROR;
}
/* dev has no statfs ops, need devfs to handle this in feature */
}
if (result != ENOERR) { if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
set_errno(EROFS);
return VFS_ERROR;
}
ret = stat(path, &buf);
if (ret != 0) {
return VFS_ERROR;
}
if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
set_errno(EACCES);
return VFS_ERROR; return VFS_ERROR;
} }
/* no access/permission control for files now, just return OK if stat is okay*/
return OK; return OK;
} }
......
...@@ -703,8 +703,6 @@ OUT: ...@@ -703,8 +703,6 @@ OUT:
int SysAccess(const char *path, int amode) int SysAccess(const char *path, int amode)
{ {
int ret; int ret;
struct stat buf;
struct statfs fsBuf;
char *pathRet = NULL; char *pathRet = NULL;
if (path != NULL) { if (path != NULL) {
...@@ -714,30 +712,9 @@ int SysAccess(const char *path, int amode) ...@@ -714,30 +712,9 @@ int SysAccess(const char *path, int amode)
} }
} }
ret = statfs((path ? pathRet : NULL), &fsBuf); ret = access(pathRet, amode);
if (ret != 0) { if (ret < 0) {
ret = -get_errno();
if (ret != -ENOSYS) {
goto OUT;
} else {
/* dev has no statfs ops, need devfs to handle this in feature */
ret = LOS_OK;
}
}
if ((fsBuf.f_flags & MS_RDONLY) && ((unsigned int)amode & W_OK)) {
ret = -EROFS;
goto OUT;
}
ret = stat((path ? pathRet : NULL), &buf);
if (ret != 0) {
ret = -get_errno(); ret = -get_errno();
goto OUT;
}
if (VfsPermissionCheck(buf.st_uid, buf.st_gid, buf.st_mode, amode)) {
ret = -EACCES;
} }
OUT: OUT:
...@@ -2149,9 +2126,6 @@ OUT: ...@@ -2149,9 +2126,6 @@ OUT:
int SysChmod(const char *pathname, mode_t mode) int SysChmod(const char *pathname, mode_t mode)
{ {
struct IATTR attr = {0};
attr.attr_chg_mode = mode;
attr.attr_chg_valid = CHG_MODE; /* change mode */
int ret; int ret;
char *pathRet = NULL; char *pathRet = NULL;
...@@ -2162,7 +2136,7 @@ int SysChmod(const char *pathname, mode_t mode) ...@@ -2162,7 +2136,7 @@ int SysChmod(const char *pathname, mode_t mode)
} }
} }
ret = chattr((pathname ? pathRet : NULL), &attr); ret = chmod(pathRet, mode);
if (ret < 0) { if (ret < 0) {
ret = -get_errno(); ret = -get_errno();
} }
...@@ -2176,8 +2150,6 @@ OUT: ...@@ -2176,8 +2150,6 @@ OUT:
int SysChown(const char *pathname, uid_t owner, gid_t group) int SysChown(const char *pathname, uid_t owner, gid_t group)
{ {
struct IATTR attr = {0};
attr.attr_chg_valid = 0;
int ret; int ret;
char *pathRet = NULL; char *pathRet = NULL;
...@@ -2188,15 +2160,7 @@ int SysChown(const char *pathname, uid_t owner, gid_t group) ...@@ -2188,15 +2160,7 @@ int SysChown(const char *pathname, uid_t owner, gid_t group)
} }
} }
if (owner != (uid_t)-1) { ret = chown(pathRet, owner, group);
attr.attr_chg_uid = owner;
attr.attr_chg_valid |= CHG_UID;
}
if (group != (gid_t)-1) {
attr.attr_chg_gid = group;
attr.attr_chg_valid |= CHG_GID;
}
ret = chattr((pathname ? pathRet : NULL), &attr);
if (ret < 0) { if (ret < 0) {
ret = -get_errno(); ret = -get_errno();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册