Process Credentials
- This is chapter 9. You should read it.
- I used a feature not in this chapter for the demo
- #include <stdlib.h>
- int mkstemp(char *template);
- This command takes a template, which must end in XXXXXX
- And includes a path reference if desired.
- and will create a unique file name (if possible)
- The file will be opened (r,w)
- And with O_EXCL
- with permissions 0600 (user read, write)
- And a file descriptor will be returned
- The template is modified after the call.
- There are other versions, but we don't need them here.
- different options for opening
- Different options for naming.
- Each process carries a number of user ids
- The real user and group id identify the user/group to which the process belongs.
- The shell gets these from /etc/passwd
- New processes inherit these from their parents.
- #include <unistd.h>
- #include <sys/types.h>
- uid_t getuid(void);
- gid_t getgid(void);
- look at myID
- run newgrp and look again.
- Effective User/Group ID
- Used when a process tries to make a privileged system call
- Used for sending signals
- Also used for file access ...
- If the effective ID is 0, the process is privileged.
- Changed via set*id
- Or setuid files.
- Set User ID files.
- A file can be marked to change the user or group id.
- This is dangerous.
- This is easy/hard
- setuid-bit, setgid bit.
- chmod u+s filename
- chmod g+s filename
- But you can't do this for a file you don't own.
- And you can't do this on some NFS mounted file systems.
- And I bet there are new security things that watch this as well.
- If these are set, the program is run with effective ids as listed.