c - 如何读取内核空间中关联的 uid 的 gids 列表?

标签 c linux linux-kernel linux-device-driver embedded-linux

我有一个基于 gid 进行身份验证的 Linux 内核驱动程序。驱动程序将获得 uid 作为输入。现在我需要获取此用户关联的所有 gid。

例如:

$ id
uid=1313(tuser) gid=1313(tuser) groups=1313(tuser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),124(sambashare)

如果驱动程序获得 1313 作为 uid,我需要读取所有 gid,即 1313,4,24,27,30,46,124

这可能吗?

最佳答案

I've a Linux kernel driver which do some authentication based on gid. The driver will get uid as input. Now I need to get all gid this user is associated.

这在内核中是不可能的,甚至是没有意义的。

UID 和 GID 之间的关系由用户空间管理。具有给定 UID 的进程通常具有 /etc/group 指定的 GID,但可能具有一组不同的 GID,具体取决于它的启动方式。

如果您需要根据 GID 进行身份验证(这听起来有点可疑,但我会放过它),您需要查看与您尝试进行身份验证的特定进程关联的 GID 列表。无法从 UID 返回该信息。

关于c - 如何读取内核空间中关联的 uid 的 gids 列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33037680/

相关文章:

linux - 将文件从 Windows 客户端复制到 Putty SSH

c - 桌面环境开发人员如何测试他的代码?

c - ICMP主机不可达

c - 外部变量声明和定义

linux - 增加 ubuntu 磁盘大小的问题(virtualbox 镜像)

linux - 在串行端口上启用内核低级调试

c - 如何使 wait_event_timeout 函数的 timeout = 1 秒?

c++ - 在 Windows 上编译 FastBoot(用于 android 用户空间刷写)

c++ - C 程序获得不同的输出?这个程序应该输出什么?

c - socket编程中AF_INET和PF_INET有什么区别?