Nucleus
Barry Signals and small task functions 9d6eb50 (3 years, 2 months ago)
diff --git a/task/uid.c b/task/uid.c
new file mode 100644
index 0000000..5b50c90
--- /dev/null
+++ b/task/uid.c
@@ -0,0 +1,95 @@
+/*
+ * This file implements the wrapper functions for setting/getting the
+ * (effective) user/group ID of the current task. These functions also check
+ * the required permission when setting any of these attributes.
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <nucleus/task.h>
+
+/* Get the current task's UID */
+uid_t
+getuid(void)
+{
+ return current->uid;
+}
+
+/* Set the current task's (E)UID */
+int
+setuid(uid_t uid)
+{
+ if (uid != current->uid
+ && uid != current->suid
+ && !super_user())
+ return -EPERM;
+ if (super_user()) {
+ current->uid = uid;
+ current->suid = uid;
+ }
+ current->euid = uid;
+ return 0;
+}
+
+/* Get the current task's EUID */
+uid_t
+geteuid(void)
+{
+ return current->euid;
+}
+
+/* Set the current task's EUID */
+int
+seteuid(uid_t euid)
+{
+ if (euid != current->uid
+ && euid != current->euid
+ && euid != current->suid
+ && !super_user())
+ return -EPERM;
+ current->euid = euid;
+ return 0;
+}
+
+/* Get the current task's GID */
+gid_t
+getgid(void)
+{
+ return current->gid;
+}
+
+/* Set the current task's (E)GID */
+int
+setgid(gid_t gid)
+{
+ if (gid != current->gid
+ && gid != current->sgid
+ && !super_user())
+ return -EPERM;
+ if (super_user()) {
+ current->gid = gid;
+ current->sgid = gid;
+ }
+ current->egid = gid;
+ return 0;
+}
+
+/* Get the current task's EGID */
+gid_t
+getegid(void)
+{
+ return current->egid;
+}
+
+/* Set the current task's EGID */
+int
+setegid(gid_t egid)
+{
+ if (egid != current->gid
+ && egid != current->egid
+ && egid != current->sgid
+ && !super_user())
+ return -EPERM;
+ current->egid = egid;
+ return 0;
+}