提交 c9d69e2d 编写于 作者: W wcc0

fix: add capability and amend smoke testcase

add setrlimit,gethostname,gethostid and capability

Change-Id: I0d5f23cb87ec2731fb79e7c5cfbe1ce109ac158a
上级 abbeca1c
......@@ -30,12 +30,14 @@
*/
#include "sys/types.h"
#include "sys/resource.h"
#include "unistd.h"
#include "stdio.h"
#include "pthread.h"
#include "sys/utsname.h"
#include "mqueue.h"
#include "semaphore.h"
#include "los_process_pri.h"
/*
......@@ -140,3 +142,47 @@ pid_t getpid(void)
return ((LosTaskCB *)(OsCurrTaskGet()))->taskID;
}
int getrlimit(int resource, struct rlimit *rlim)
{
LosProcessCB *pcb = OsCurrProcessGet();
switch (resource) {
case RLIMIT_NOFILE:
case RLIMIT_FSIZE:
break;
default:
return -EINVAL;
}
rlim->rlim_cur = pcb->pl_rlimit[resource].rlim_cur;
rlim->rlim_max = pcb->pl_rlimit[resource].rlim_max;
return 0;
}
#define FSIZE_RLIMIT 0XFFFFFFFF
int setrlimit(int resource, const struct rlimit *rlim)
{
LosProcessCB *pcb = OsCurrProcessGet();
if (rlim->rlim_cur > rlim->rlim_max) {
return -EINVAL;
}
switch (resource) {
case RLIMIT_NOFILE:
if (rlim->rlim_max > NR_OPEN_DEFAULT) {
return -EPERM;
}
break;
case RLIMIT_FSIZE:
if (rlim->rlim_max > FSIZE_RLIMIT) {
return -EPERM;
}
break;
default:
return -EINVAL;
}
pcb->pl_rlimit[resource].rlim_cur = rlim->rlim_cur;
pcb->pl_rlimit[resource].rlim_max = rlim->rlim_max;
return 0;
}
\ No newline at end of file
......@@ -45,6 +45,7 @@
#ifdef LOSCFG_SECURITY_VID
#include "vid_type.h"
#endif
#include "sys/resource.h"
#ifdef __cplusplus
#if __cplusplus
......@@ -126,6 +127,7 @@ typedef struct ProcessCB {
#ifdef LOSCFG_KERNEL_CPUP
OsCpupBase processCpup; /**< Process cpu usage */
#endif
struct rlimit pl_rlimit[RLIM_NLIMITS];
} LosProcessCB;
#define CLONE_VM 0x00000100
......
......@@ -66,4 +66,4 @@
#define CAP_REBOOT 18
// self deined privileged syscalls
#define CAP_SHELL_EXEC 19
#endif
\ No newline at end of file
#endif
......@@ -287,5 +287,8 @@ extern int SysUmask(int mask);
extern int SysShellExec(const char *msgName, const char *cmdString);
extern int SysReboot(int magic, int magic2, int type);
extern int SysGetrusage(int what, struct rusage *ru);
extern long SysSysconf(int name);
extern int SysUgetrlimit(int resource, unsigned long long k_rlim[2]);
extern int SysSetrlimit(int resource, unsigned long long k_rlim[2]);
#endif
#endif /* _LOS_SYSCALL_H */
......@@ -45,6 +45,10 @@
#include "shmsg.h"
#endif
#include "user_copy.h"
#include "los_strncpy_from_user.h"
#include "capability_type.h"
#include "capability_api.h"
#include "unistd.h"
int SysUname(struct utsname *name)
......@@ -193,3 +197,50 @@ int SysGetrusage(int what, struct rusage *ru)
return 0;
}
long SysSysconf(int name)
{
long ret;
ret = sysconf(name);
if (ret == -1) {
return -get_errno();
}
return ret;
}
int SysUgetrlimit(int resource, unsigned long long k_rlim[2])
{
int ret;
struct rlimit lim;
ret = getrlimit(resource, &lim);
if (ret < 0) {
return ret;
}
ret = LOS_ArchCopyToUser(k_rlim, &lim, sizeof(struct rlimit));
if (ret != 0) {
return -EFAULT;
}
return ret;
}
int SysSetrlimit(int resource, unsigned long long k_rlim[2])
{
int ret;
struct rlimit lim;
if(!IsCapPermit(CAP_CAPSET)) {
return -EPERM;
}
ret = LOS_ArchCopyFromUser(&lim, k_rlim, sizeof(struct rlimit));
if (ret != 0) {
return -EFAULT;
}
ret = setrlimit(resource, &lim);
return ret;
}
......@@ -246,3 +246,6 @@ SYSCALL_HAND_DEF(__NR_pthread_join, SysThreadJoin, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_pthread_deatch, SysUserThreadDetach, int, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_creat_user_thread, SysCreateUserThread, unsigned int, ARG_NUM_3)
SYSCALL_HAND_DEF(__NR_getrusage, SysGetrusage, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_sysconf, SysSysconf, long, ARG_NUM_1)
SYSCALL_HAND_DEF(__NR_ugetrlimit, SysUgetrlimit, int, ARG_NUM_2)
SYSCALL_HAND_DEF(__NR_setrlimit, SysSetrlimit, int, ARG_NUM_2)
\ No newline at end of file
......@@ -44,6 +44,8 @@ sources_entry = [
sources_full = [
"full/misc_test_006.cpp",
"full/misc_test_007.cpp",
"full/misc_test_008.cpp",
"full/misc_test_009.cpp",
"full/misc_test_010.cpp",
"full/misc_test_011.cpp",
"full/misc_test_012.cpp",
......@@ -56,8 +58,6 @@ sources_smoke = [
"smoke/misc_test_003.cpp",
"smoke/misc_test_004.cpp",
"smoke/misc_test_005.cpp",
"smoke/misc_test_008.cpp",
"smoke/misc_test_009.cpp",
"smoke/misc_test_014.cpp",
]
......@@ -86,4 +86,4 @@ if (LOSCFG_USER_TEST_LEVEL >= TEST_LEVEL_MIDDLE) {
configs = [ "..:public_config_for_all" ]
deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
}
}
\ No newline at end of file
}
......@@ -128,10 +128,32 @@ HWTEST_F(MiscTest, ItTestMisc006, TestSize.Level0)
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
/*HWTEST_F(MiscTest, ItTestMisc007, TestSize.Level0)
HWTEST_F(MiscTest, ItTestMisc007, TestSize.Level0)
{
ItTestMisc007();
}*/
}
/* *
* @tc.name: IT_TEST_MISC_008
* @tc.desc: function for MiscTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(MiscTest, ItTestMisc008, TestSize.Level0)
{
ItTestMisc008();
}
/* *
* @tc.name: IT_TEST_MISC_009
* @tc.desc: function for MiscTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(MiscTest, ItTestMisc009, TestSize.Level0)
{
ItTestMisc009();
}
/* *
* @tc.name: IT_TEST_MISC_010
......@@ -155,6 +177,17 @@ HWTEST_F(MiscTest, ItTestMisc006, TestSize.Level0)
ItTestMisc011();
}*/
/* *
* @tc.name: IT_TEST_MISC_012
* @tc.desc: function for MiscTest
* @tc.type: FUNC
* @tc.require: AR000EEMQ9
*/
HWTEST_F(MiscTest, ItTestMisc012, TestSize.Level0)
{
ItTestMisc012();
}
/* *
* @tc.name: IT_TEST_MISC_013
* @tc.desc: function for MiscTest
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册