zoukankan      html  css  js  c++  java
  • SetUserID and SetGroupID(4.4)

    Every process has six or more IDs associated with it. These are shown in Figure 4.5.

                           Figure 4.5. User IDs and group IDs associated with each process

    real user ID
    real group ID

    who we really are

    effective user ID
    effective group ID
    supplementary group IDs

    used for file access permission checks

    saved set-user-ID
    saved set-group-ID

    saved by exec functions

    • The real user ID and real group ID identify who we really are. These two fields are taken from our entry in the password file when we log in. Normally, these values don't change during a login session, although there are ways for a superuser process to change them, which we describe in Section 8.11.

    • The effective user ID, effective group ID, and supplementary group IDs determine our file access permissions, as we describe in the next section. (We defined supplementary group IDs in Section 1.8.)

    • The saved set-user-ID and saved set-group-ID contain copies of the effective user ID and the effective group ID when a program is executed. We describe the function of these two saved values when we describe the setuid function in Section 8.11.

      The saved IDs are required with the 2001 version of POSIX.1. They used to be optional in older versions of POSIX. An application can test for the constant _POSIX_SAVED_IDS at compile time or can call sysconf with the _SC_SAVED_IDS argument at runtime, to see whether the implementation supports this feature.

    Normally, the effective user ID equals the real user ID, and the effective group ID equals the real group ID.

    Every file has an owner and a group owner. The owner is specified by the st_uid member of the stat structure; the group owner, by the st_gid member.

    When we execute a program file, the effective user ID of the process is usually the real user ID, and the effective group ID is usually the real group ID. But the capability exists to set a special flag in the file's mode word (st_mode) that says "when this file is executed, set the effective user ID of the process to be the owner of the file (st_uid)." Similarly, another bit can be set in the file's mode word that causes the effective group ID to be the group owner of the file (st_gid). These two bits in the file's mode word are called the set-user-ID bit and the set-group-ID bit (if you use 'ls -l' to examine a file with the two bits set, it shows sort of'-rwsrws---' ).

    For example, if the owner of the file is the superuser and if the file's set-user-ID bit is set, then while that program file is running as a process, it has superuser privileges. This happens regardless of the real user ID of the process that executes the file. As an example, the UNIX System program that allows anyone to change his or her password, passwd(1), is a set-user-ID program. This is required so that the program can write the new password to the password file, typically either /etc/passwd or /etc/shadow, files that should be writable only by the superuser. Because a process that is running set-user-ID to some other user usually assumes extra permissions, it must be written carefully. We'll discuss these types of programs in more detail in Chapter 8.

    Returning to the stat function, the set-user-ID bit and the set-group-ID bit are contained in the file's st_mode value. These two bits can be tested against the constants S_ISUID and S_ISGID.


    作者:beanmoon
    出处:http://www.cnblogs.com/beanmoon/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接。
    该文章也同时发布在我的独立博客中-豆月博客

  • 相关阅读:
    Ajax基础
    css基础
    响应式容器布局
    PHP基础
    Unity 3d 刚体
    ASP.NET 大文件下载的实现思路及代码
    2015年第一篇 自律守则以及年度目标
    ItextSharp代码示例
    HTML5 新增通用属性
    c# 委托实例
  • 原文地址:https://www.cnblogs.com/beanmoon/p/2713428.html
Copyright © 2011-2022 走看看