"Linux Advanced Programming" (chapter eighth) process management and program development 4

Source: Internet
Author: User

Modify process user-related information

int access (__const char *__name, int __type): Detects whether the current process has access to a file

Parameter 1: Files to be accessed

Parameter 2: corresponding permission 4 (R_ok readable), 2 (W_ok writable), 1 (X_OK executable), 0 (F_OK file exists)

Returns 0 if it has permission, otherwise 1. Error status includes eacces (no access), ENOENT (file does not exist), erofs (read-only file system requires write permission)

int i; if ((i = Access ("/etc/exports", x_ok)) = =-1) {    perror ("  Access");    Exit (exit_failure);} Else {    //...}

int setuid (__uid_t __uid): Set process Real user Ruid

The real user number with the preset value.

Super User execution: will set the real user number UID, valid user number Euid to the specified ID, and return 0 for success.

Normal user execution: If set to its own UID value, can be successful; otherwise not authorized to modify, return-1.

#include <stdio.h>#include<unistd.h>#include<stdlib.h>intMain () {intuid, euid, suid; Getresuid (&uid, &euid, &suid); printf ("uid =%d, Euid =%d, suid =%d\n", UID, euid, suid); printf ("After setuid (501) \ n"); Setuid (501); UID= -1; Euid= -1; Suid= -1; Getresuid (&uid, &euid, &suid); printf ("uid =%d, Euid =%d, suid =%d\n", UID, euid, suid); return 0;}

Root user execution results, can be successfully modified

Normal user execution results, non-modifiable

int Setgid (__gid_t __gid): The GID of the process user has been modified, using the same method as setuid.

int Seteuid (__uid_t __uid): Set Valid user number Euid

Super User: Set valid user number to the specified ID, successfully returned 0, failed to return-1;

Normal User: Can be set to its own ID, set to another failure.

int Setegid (__gid_t __gid): Set valid user group ID

int Setreuid (__uid_t __ruid, __uid_t __euid): Set Ruid and Euid at the same time

int Setregid (__gid_t __rgid, __gid_t __egid): Set up both real user groups and active user groups

"Linux Advanced Programming" (chapter eighth) process management and program development 4

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.