简体   繁体   中英

in kernel program get root user id and compare with current user id

As we know, the root uid is 0. so I tried to compare current process uid with 0. as follows:

uid_eq(get_current_cred()->uid, 0)

however, I get incompatible type for argument 2 of 'uid_eq'

I have also tried

uid_eq(get_current_cred()->uid, (kuid_t)0)

but this also give this error: conversion to non-scalar type requested

How should I check if the current process is root in kernel? Thank you.

kuid_t is a struct, so you should declare one, and set it's val member to 0 .

Try this

kuid_t rootUid;

rootUid.val = 0;
uid_eq(get_current_cred()->uid, rootUid);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM