Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get username from Linux kernel space

I am doing some Linux module development, restricting me to only kernel-available libraries, and I'd like to get the username of the user who is interacting with my module's username. AKA their "whoami". My module is actually wrapping around syscalls... I can get pid's from current->pid in kernel space. Is there any way to, perhaps, use the pid to track down the user to whom the pid belongs? Or another more simple way?

Thanks

like image 628
PinkElephantsOnParade Avatar asked Oct 18 '12 18:10

PinkElephantsOnParade


1 Answers

You can use the filp_open function to open /etc/passwd file from the kernel. Next you'll need to use the file_operations to read the file:

struct file * file = filp_open(...);
file->f_op->read(file, ...);

Reading the file contents may be helpful for UID -> username translation.

like image 116
Ilya Matveychikov Avatar answered Nov 10 '22 22:11

Ilya Matveychikov