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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With