[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and isse
From: |
Karim Taha |
Subject: |
[PATCH v4 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid. |
Date: |
Mon, 25 Sep 2023 00:01:24 +0300 |
From: Stacey Son <sson@FreeBSD.org>
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>
---
bsd-user/bsd-proc.h | 76 +++++++++++++++++++++++++++++++++++
bsd-user/freebsd/os-syscall.c | 28 +++++++++++++
2 files changed, 104 insertions(+)
diff --git a/bsd-user/bsd-proc.h b/bsd-user/bsd-proc.h
index 6ff07c0ac3..a5f301c72f 100644
--- a/bsd-user/bsd-proc.h
+++ b/bsd-user/bsd-proc.h
@@ -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_ */
diff --git a/bsd-user/freebsd/os-syscall.c b/bsd-user/freebsd/os-syscall.c
index 7565e69e76..7b51f4f16e 100644
--- a/bsd-user/freebsd/os-syscall.c
+++ b/bsd-user/freebsd/os-syscall.c
@@ -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.
--
2.42.0
- Re: [PATCH v4 06/28] bsd-user: Implement target_to_host_resource conversion function, (continued)
- [PATCH v4 07/28] bsd-user: Implement target_to_host_rlim and host_to_target_rlim conversion., Karim Taha, 2023/09/24
- [PATCH v4 09/28] bsd-user: Implement host_to_target_waitstatus conversion., Karim Taha, 2023/09/24
- [PATCH v4 08/28] bsd-user: Implement host_to_target_rusage and host_to_target_wrusage., Karim Taha, 2023/09/24
- [PATCH v4 10/28] bsd-user: Get number of cpus., Karim Taha, 2023/09/24
- [PATCH v4 11/28] bsd-user: Implement getgroups(2) and setgroups(2) system calls., Karim Taha, 2023/09/24
- [PATCH v4 12/28] bsd-user: Implement umask(2), setlogin(2) and getlogin(2), Karim Taha, 2023/09/24
- [PATCH v4 13/28] bsd-user: Implement getrusage(2)., Karim Taha, 2023/09/24
- [PATCH v4 14/28] bsd-user: Implement getrlimit(2) and setrlimit(2), Karim Taha, 2023/09/24
- [PATCH v4 16/28] bsd-user: Implement get/set[resuid/resgid/sid] and issetugid.,
Karim Taha <=
- [PATCH v4 15/28] bsd-user: Implement several get/set system calls:, Karim Taha, 2023/09/24
- [PATCH v4 19/28] bsd-user: Implement get_filename_from_fd., Karim Taha, 2023/09/24
- [PATCH v4 17/28] bsd-user: Add stubs for profil(2), ktrace(2), utrace(2) and ptrace(2)., Karim Taha, 2023/09/24
- [PATCH v4 18/28] bsd-user: Implement getpriority(2) and setpriority(2)., Karim Taha, 2023/09/24
- [PATCH v4 20/28] bsd-user: Implement freebsd_exec_common, used in implementing execve/fexecve., Karim Taha, 2023/09/24
- [PATCH v4 21/28] bsd-user: Implement procctl(2) along with necessary conversion functions., Karim Taha, 2023/09/24
- [PATCH v4 22/28] bsd-user: Implement execve(2) and fexecve(2) system calls., Karim Taha, 2023/09/24
- [PATCH v4 23/28] bsd-user: Implement wait4(2) and wait6(2) system calls., Karim Taha, 2023/09/24