How does su regulate app permissions? I seen a lot of apps in the market that give superuser functionality to applications. However there is a pre-requisite of rooting your phone. I am curious how a rooted phone has those permissions already?

I've downloaded the source code and have managed to locate the su.c file that might invoke an application to change. But im still not sure. Can anyone give an insight on this? 

Which actual files delegate permissions? Are all system apps given root permissions at startup?
Once upon a time, there is a walled city with a large, closed gate bound by magical lock that can only be opened with a magical sword. According to the cityfolk's traditions, anyone who brings the magic sword and unlocked the magical gate is destined to be the lord of the city.

One day, a young hero comes to the city, bringing with him the magical sword he took from the root of the Yggdrasil tree. He tapped the sword lightly on the door, and immediately the magical gate unlocked itself and peered open. The cityfolks cheered, and as per their tradition, they anointed the young hero as the city's lord.

As a city lord, there are many tasks he had to do, one of which is to ensure the security of his people, especially now that the gate is open and bandits and thieves may attempt to enter the city and rob the cityfolks' of their belongings.

To ensure the peaceful days of the cityfolks, the wise lord hired a trusted SU manager to guard the gate; dutifully, the SU manager enters the city, and he closed the gate behind him, and he put a lock that only he can open, then he creates a big door knob for strangers to knock the gate, a small hole on the door where he can peek outside and look at the strangers, then asks the city's lord whether or not to allow strangers in.

In eternity, the wise lord ruled the city for a long time and the cityfolks lives happily ever after.