How to get userID when writing Linux kernel module

后端 未结 4 2074
伪装坚强ぢ
伪装坚强ぢ 2020-12-30 16:13

Here is my function in my kernel module which I insert using insmod command after make at later stages. I am working on goldfish (2.6.29)

4条回答
  •  粉色の甜心
    2020-12-30 16:56

    You could perhaps use this:

     #include 
    
     static int getuid()
     {
         return current_uid();
     }
    

    cred stands for "credentials", and this macro returns the user-id of the currently active credentials. Bear in mind however that the "current user id" can mean multiple things in Linux.

    [dan3 obviously didn't have to dig through quite as much code as I did to find this - or he started before me!]

提交回复
热议问题