bsd-user: Implement get/set[resuid/resgid/sid] and issetugid.

Signed-off-by: Stacey Son <sson@FreeBSD.org>
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Warner Losh <imp@bsdimp.com>
Message-Id: <20230925182425.3163-17-kariem.taha2.7@gmail.com>
This commit is contained in:
Stacey Son 2023-09-25 21:24:13 +03:00 committed by Warner Losh
parent e4446e0a2c
commit 932683c3d4
2 changed files with 104 additions and 0 deletions

View File

@ -286,4 +286,80 @@ static inline abi_long do_bsd_setregid(abi_long arg1, abi_long arg2)
return get_errno(setregid(arg1, arg2));
}
/* setresgid(2) */
static inline abi_long do_bsd_setresgid(gid_t rgid, gid_t egid, gid_t sgid)
{
return get_errno(setresgid(rgid, egid, sgid));
}
/* setresuid(2) */
static inline abi_long do_bsd_setresuid(uid_t ruid, uid_t euid, uid_t suid)
{
return get_errno(setresuid(ruid, euid, suid));
}
/* getresuid(2) */
static inline abi_long do_bsd_getresuid(abi_ulong arg1, abi_ulong arg2,
abi_ulong arg3)
{
abi_long ret;
uid_t ruid, euid, suid;
ret = get_errno(getresuid(&ruid, &euid, &suid));
if (is_error(ret)) {
return ret;
}
if (put_user_s32(ruid, arg1)) {
return -TARGET_EFAULT;
}
if (put_user_s32(euid, arg2)) {
return -TARGET_EFAULT;
}
if (put_user_s32(suid, arg3)) {
return -TARGET_EFAULT;
}
return ret;
}
/* getresgid(2) */
static inline abi_long do_bsd_getresgid(abi_ulong arg1, abi_ulong arg2,
abi_ulong arg3)
{
abi_long ret;
uid_t ruid, euid, suid;
ret = get_errno(getresgid(&ruid, &euid, &suid));
if (is_error(ret)) {
return ret;
}
if (put_user_s32(ruid, arg1)) {
return -TARGET_EFAULT;
}
if (put_user_s32(euid, arg2)) {
return -TARGET_EFAULT;
}
if (put_user_s32(suid, arg3)) {
return -TARGET_EFAULT;
}
return ret;
}
/* getsid(2) */
static inline abi_long do_bsd_getsid(abi_long arg1)
{
return get_errno(getsid(arg1));
}
/* setsid(2) */
static inline abi_long do_bsd_setsid(void)
{
return get_errno(setsid());
}
/* issetugid(2) */
static inline abi_long do_bsd_issetugid(void)
{
return get_errno(issetugid());
}
#endif /* !BSD_PROC_H_ */

View File

@ -315,6 +315,34 @@ static abi_long freebsd_syscall(void *cpu_env, int num, abi_long arg1,
ret = do_bsd_setregid(arg1, arg2);
break;
case TARGET_FREEBSD_NR_getresuid: /* getresuid(2) */
ret = do_bsd_getresuid(arg1, arg2, arg3);
break;
case TARGET_FREEBSD_NR_getresgid: /* getresgid(2) */
ret = do_bsd_getresgid(arg1, arg2, arg3);
break;
case TARGET_FREEBSD_NR_setresuid: /* setresuid(2) */
ret = do_bsd_setresuid(arg1, arg2, arg3);
break;
case TARGET_FREEBSD_NR_setresgid: /* setresgid(2) */
ret = do_bsd_setresgid(arg1, arg2, arg3);
break;
case TARGET_FREEBSD_NR_getsid: /* getsid(2) */
ret = do_bsd_getsid(arg1);
break;
case TARGET_FREEBSD_NR_setsid: /* setsid(2) */
ret = do_bsd_setsid();
break;
case TARGET_FREEBSD_NR_issetugid: /* issetugid(2) */
ret = do_bsd_issetugid();
break;
/*
* File system calls.