summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2025-07-09 01:06:07 -0400
committerIan Moffett <ian@osmora.org>2025-07-09 01:06:07 -0400
commitee2e8661148b7e9fe1413a714fdf8779f867afc0 (patch)
tree82a6be2b540b6f3bcf462da6fa36d616304f4127
parentda2bcd5b6a651ad6aa81a94d51b8e3cc61652569 (diff)
kernel: proc: Add initial setuid()
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/include/sys/ucred.h1
-rw-r--r--sys/kern/kern_cred.c57
2 files changed, 58 insertions, 0 deletions
diff --git a/sys/include/sys/ucred.h b/sys/include/sys/ucred.h
index 32eb9b3..ef66a18 100644
--- a/sys/include/sys/ucred.h
+++ b/sys/include/sys/ucred.h
@@ -46,4 +46,5 @@ struct ucred {
#endif /* _KERNEL */
};
+int setuid(uid_t new);
#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/kern/kern_cred.c b/sys/kern/kern_cred.c
new file mode 100644
index 0000000..828ba3b
--- /dev/null
+++ b/sys/kern/kern_cred.c
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/types.h>
+#include <sys/errno.h>
+#include <sys/ucred.h>
+#include <sys/proc.h>
+
+int
+setuid(uid_t new)
+{
+ struct proc *td;
+ struct ucred *cur_cred;
+
+ td = this_td();
+ cur_cred = &td->cred;
+
+ /*
+ * Only root can become other users. If you are not
+ * root, fuck off.
+ */
+ if (cur_cred->ruid != 0) {
+ return -EPERM;
+ }
+
+ spinlock_acquire(&cur_cred->lock);
+ cur_cred->euid = new;
+ cur_cred->ruid = new;
+ spinlock_release(&cur_cred->lock);
+ return 0;
+}