BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / blob / master / task / uid.c

// Related

Nucleus

Barry System headers (remove libc dependency) 18495cf (3 years, 2 months ago)
/*
 * 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/errno.h>
#include <sys/types.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;
}