关于Linux中使用geteuid()返回值uid_t参数值的问题

青冥遗落 2015-12-24 09:31:42
刚学不久linux,写who am i的时候发现网上不少答案用的都是geteuid()获得有效用户,看了下man帮助,这么显示的:

GETUID(2) Linux Programmer's Manual GETUID(2)

NAME
getuid, geteuid - get user identity

SYNOPSIS
#include <unistd.h>
#include <sys/types.h>

uid_t getuid(void);
uid_t geteuid(void);

DESCRIPTION
getuid() returns the real user ID of the calling process.

geteuid() returns the effective user ID of the calling process.

ERRORS
These functions are always successful.

CONFORMING TO
POSIX.1-2001, 4.3BSD.

NOTES
History
In UNIX V6 the getuid() call returned (euid << 8) + uid. UNIX V7
introduced separate calls getuid() and geteuid().

The original Linux getuid() and geteuid() system calls supported only
16-bit user IDs. Subsequently, Linux 2.4 added getuid32() and
geteuid32(), supporting 32-bit IDs. The glibc getuid() and geteuid()
wrapper functions transparently deal with the variations across kernel
versions.

SEE ALSO
getresuid(2), setreuid(2), setuid(2), credentials(7)

COLOPHON
This page is part of release 3.54 of the Linux man-pages project. A
description of the project, and information about reporting bugs, can
Manual page geteuid(2) line 1 (press h for help or q to quit)

比较疑惑uid_t这个返回类型,我不清楚会返回几个用户的信息,想问问首先有效用户应该不会只有自己吧,另外返回的话每次调用geteuid()会返回几个用户的信息呢?还是要怎么依次访问?
...全文
613 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhxianbin 2015-12-25
  • 打赏
  • 举报
回复
typedef __kernel_uid32_t uid_t; typedef unsigned int __kernel_uid32_t; uid_t 是 unsigned int 类型的
cl55 2015-12-25
  • 打赏
  • 举报
回复
这两个都只返回一个用户。 getuid 返回当前进程的用户 geteuid 返回有效用户,也就是说被运行的程序以它的owner做为有效用户,所以运行这个程序的用户可以间接访问到有效用户才能访问到的资源

4,465

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧