The uropygial gland is located at the base of the birds tail. It secretes the oil that the bird uses to preen its feathers with. Ever noticed that a duck will rub its bill at the base of it's tail before preening its feathers? The oil gets on the bill/beak and the bird then transfers this oil to all its feathers. The oil acts as a barrier against water, dirt etc. A lot of this has to do with chemical bonding as well. You know, water and oil don't mix and so forth. Feathers also have hooks and barbs that hold the vanes tightly together, mostly for flying, but I'm sure it also helps repel dirt and water.