I am writing linux kernel code. I am in VFS and I want to modify it. I want to add a check to see whether or not the user is root and based on that make a decision. How do I do this? Is there a kernel version of getuid() ? Or does any structure like "current->" contain info on which user it is for the current process?
You can use current_cred()
as defined in include/linux/cred.h
, which will give you a pointer to a struct cred
itself defined in the same header. Something like
if (current_cred()->uid != 0)
return -EPERM;
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