c - determine the user who run the current process -
this question has answer here:
- check if user root in c? 2 answers
i wonder, how can determine if current process running root or not. after searching on google, found out linux has field called "current" can use determine running particular process. try use
current->uid == 0
however, when try compile code error
struct task_structâ has no member named âuidâ
did wrong? additionally, true if process run root, uid equal zero? thanks
for process ,it have 3 kind of user id:
1.actual user id
--> of time are, man login , while root process has way change it.
use getuid()
user id.
2.effective user id
-->this id decide access limits. exce
function can set id ,and if didn't, user id same actual user id.
use geteuid()
id
3.saved settings user id
--> copyed effective user id exec
function. no function id's current value.at least , don't know.
so
how can determine if current process running root or not
if mean running as root ,use geteuid() == 0
better, opinion.
Comments
Post a Comment