The tale of Ali Baba is one of those generic stories, the details of which tend to be pretty loose: there are 40 thieves, there's a magical cave with the password 'open sesame', and there's a chap called Ali Baba who starts out poor and miserable and ends up rich and happy and gets the girl.