What do "sama" and "kun" mean? Are they related to the shinobi rank? In Naruto, Yamato called Kakashi as Kakashi-sama, whereas Naruto as Naruto-kun.

Previously, I thought that sama was for equal or higher rank shinobis while kun was for junior rank shinobis. But I noticed that I might be wrong as Hinata too called Naruto as Naruto-kun.

I found some general answers on Yahoo! Answers, but is there a specific reason why they did that in Naruto? What's the actual meaning of sama and kun?
Both terms are Japanese honorifics.

Sama (様) is the formal version of "san", used for persons in higher positions (inferiors to superiors). On the other hand, kun (君) is informal and mostly used for males, such as boys or juniors. It is used by superiors to inferiors, by males of the same age and status to each other. In schools, teachers address male students as "kun" while girls as "san" or "chan".

As for anime Naruto, Yamato called Kakashi as Kakashi-sama simply because of respect for the higher position. Kakashi is a lot experienced than him. Meanwhile, Hinata called Naruto with "kun" as an informal honorific for a boy with the same age, that applies too for kun.