A simple explanation of the correlation function of user identification code in C language _c language

Source: Internet
Author: User

C language Setuid () function: Set the real user identification code

Header file:

#include <unistd.h>

To define a function:

int setuid (uid_t uid);

Function Description:
Setuid () is used to reset the user ID code that executes the current process. However, for this function to work, its valid user identification code must be 0 (root). Under Linux, when Root uses setuid () to convert to other user identifiers, root permissions are discarded and completely converted to the user's identity, that is, the process will no longer have the right to setuid (), if only to temporarily discard root permissions, later want to regain the right Limit, you must use Seteuid ().

Return value: Returns 0 for successful execution, failure returns 1, and error code is stored in errno.

Additional note: Generally in the preparation of the program with setuid root, in order to reduce the system security risks caused by such programs, after the use of root permissions recommended immediately execute setuid (Getuid ()), to discard root permissions. In addition, the Linux system will not produce core dump when the process UID and euid are inconsistent.

C language Setreuid () function: Setting up a real and valid user identification code

Header file:

#include <unistd.h>

To define a function:

int Setreuid (uid_t ruid, uid_t euid);

Function Description: Setreuid () is used to set the parameter Ruid as the real user identification code of the current process, and the parameter euid is established as a valid user identification code for the current process. If the parameter ruid or Euid value is-1, the corresponding identifier does not change.

Return value: Returns 0 for successful execution, failure returns 1, and error code is stored in errno.

C language Setfsuid () function: Setting the user ID of the file system
header file:

 #include <unistd.h>

To define a function:

int Setfsuid (uid_t fsuid);

Function Description: Setfsuid () is used to reset the user ID of the file system for the current process. In general, the file system's user identification Code (FSUID) is the same as a valid user identification code (EUID). If this function is invoked by a superuser, the parameter fsuid can be any value, otherwise the parameter fsuid must be one of Real/effective/saved's user identifiers.

Return value: Returns 0 for successful execution, failure returns-1, error code is stored in errno additional description This function is Linux specific

Error code:
Eperm: Insufficient permissions to complete Setup.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.