For OS X Features: Have you looked at the Authentication, Authorization, and Permissions Guide for Mac OS X?
Typically, on UNIX-like operating systems, processes usually belong to one specific user, and what they are allowed to do is largely determined by this. There are some exceptions to this, but as a rule, the idea, as a rule, is to do this for the granularity of each process. On the plus side, starting new processes is very simple - see the fork() function .
Thus, a typical way for a daemon (for example, sshd) to impersonate other users is to start the main process with root privileges. Then accept the incoming connections and pass them to the child processes fork() ed, which, as you say, immediately give privileges with set * uid. There are various communication channels between processes, such as channels that you can configure if child processes must interact with the parent process. Obviously, the less code that runs as root, the better, from a security point of view, so you want child processes to be autonomous.
If you need users who really provide their username and password, things get a little more complicated; you can look at the source code for the su and sudo utilities and read the platform documentation for the authentication API.
source share