I have added a system call to Linux kernel that looks like this:
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/cred.h>
#include <asm/uaccess.h>
asmlinkage int sys_os_pid_to_uid(int pid, int* puid)
{
struct task_struct* task;
rcu_read_lock();
for_each_process(task)
{
if (task->pid == (pid_t) pid)
{
copy_to_user(puid, &(task->cred->uid.val), sizeof(task->cred->uid.val));
}
}
rcu_read_unlock();
return 0;
}
It gets a process ID (pid
) and determines the user ID (puid
) of the user who is executing it.
Now, my problem begins: I want to add another argument to this system call, that is, char *username
, which will contain the username of the user whose ID is puid
. I searched in the cred.h
header but was unable to find anything concerned with the username.
Can anyone help me solve this?