Obviously it only makes sense to buy back shares if they are at or below fair value.
Hence Buffetts activity,as Rick describes.
The other situation would be a company who (through share price decline) is paying a 7+% dividend.
Maybe it sees better income days ahead...but if it needs new capital and can obtain it at a lower rate in the bond market,it might well also use some of that new $ to  buy/cancel some shares, as they are essentially 7% notes.
I would think however the bond issuers would prefer to see the dividend cut also....so its not a "one case fits all"
Is it mostly done to goose EPS etc in the short term ??......probably.
The smartest share buyback is often taking a (good) company private.
For some reason that is quite rare these days :)