Enabling directory

I have seen companies which has IP handsets and can browse thru the company directory. Just want to understand if these data came from asterisk itself where it can be passed thru the phone or thru Active Directory / LDAP server? I am only using ATA and soft phones so I don’t bother much. But its good to know how this works so I can do when I will deploy on large scale in the future.