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