summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-09 19:59:37 -0400
committerIan Moffett <ian@osmora.org>2025-07-09 21:05:51 -0400
commite57f9bf6ca7fa27b6d44029658d565ae093606b8 (patch)
tree1dd7b2151da759b19674c56f1ba600d80ec9cc33 /sys
parent252c90732709447ad33bbf329fc47d584cd23f37 (diff)
kernel: ucred: Add SYS_getuid
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'sys')
-rw-r--r--sys/include/sys/syscall.h1
-rw-r--r--sys/include/sys/ucred.h2
-rw-r--r--sys/kern/kern_cred.c19
-rw-r--r--sys/kern/kern_syscall.c1
4 files changed, 23 insertions, 0 deletions
diff --git a/sys/include/sys/syscall.h b/sys/include/sys/syscall.h
index 05288f4..51c2579 100644
--- a/sys/include/sys/syscall.h
+++ b/sys/include/sys/syscall.h
@@ -57,6 +57,7 @@
#define SYS_getpid 16
#define SYS_getppid 17
#define SYS_setuid 18
+#define SYS_getuid 19
#if defined(_KERNEL)
/* Syscall return value and arg type */
diff --git a/sys/include/sys/ucred.h b/sys/include/sys/ucred.h
index b44a7fe..f8cbbe0 100644
--- a/sys/include/sys/ucred.h
+++ b/sys/include/sys/ucred.h
@@ -48,8 +48,10 @@ struct ucred {
};
int setuid(uid_t new);
+uid_t getuid(void);
#if defined(_KERNEL)
scret_t sys_setuid(struct syscall_args *scargs);
+scret_t sys_getuid(struct syscall_args *scargs);
#endif
#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/kern/kern_cred.c b/sys/kern/kern_cred.c
index e1202fc..017b22a 100644
--- a/sys/kern/kern_cred.c
+++ b/sys/kern/kern_cred.c
@@ -56,6 +56,19 @@ setuid(uid_t new)
return 0;
}
+uid_t
+getuid(void)
+{
+ struct proc *td;
+
+ td = this_td();
+ if (td == NULL) {
+ return -1;
+ }
+
+ return td->cred.ruid;
+}
+
/*
* setuid() syscall
*
@@ -66,3 +79,9 @@ sys_setuid(struct syscall_args *scargs)
{
return setuid(scargs->arg0);
}
+
+scret_t
+sys_getuid(struct syscall_args *scargs)
+{
+ return getuid();
+}
diff --git a/sys/kern/kern_syscall.c b/sys/kern/kern_syscall.c
index 276c7c7..a28d2dd 100644
--- a/sys/kern/kern_syscall.c
+++ b/sys/kern/kern_syscall.c
@@ -58,6 +58,7 @@ scret_t(*g_sctab[])(struct syscall_args *) = {
sys_getpid, /* SYS_getpid */
sys_getppid, /* SYS_getppid */
sys_setuid, /* SYS_setuid */
+ sys_getuid, /* SYS_getuid */
};
const size_t MAX_SYSCALLS = NELEM(g_sctab);